elasticsearch - elasticsearch7.x 索引孙文档
问题描述
最近在研究elasticsearch 7.x中的祖孙文档。我自己建了一个索引,往里面插入了数据(见下面的代码),但是发现好像查不到数据,是不是我做错了什么?谢谢
映射:</p>
PUT /map
{
"mappings": {
"properties": {
"country": {
"properties": {
"id": {
"type": "integer"
},
"countryName": {
"type": "text"
}
}
},
"province": {
"properties": {
"id": {
"type": "integer"
},
"provinceName": {
"type": "text"
}
}
},
"city": {
"properties": {
"id": {
"type": "integer"
},
"cityName": {
"type": "text"
},
"attractions": {
"type": "text"
}
}
},
"my_join_field": {
"type": "join",
"relations": {
"country": "province",
"province": "city"
}
}
}
}
}
文件:
PUT map/_doc/1?refresh
{
"country.id": "1",
"country.countryName": "US",
"relationship": {
"name": "country"
}
}
PUT map/_doc/2?refresh
{
"country.id": "2",
"country.countryName": "CHINA",
"relationship": {
"name": "country"
}
}
PUT map/_doc/3?routing=1&refresh
{
"province.id": "3",
"province.provinceName": "losangeles",
"relationship": {
"name": "province",
"parent": "1"
}
}
PUT map/_doc/4?routing=1&refresh
{
"province.id": "4",
"province.provinceName": "chicago",
"relationship": {
"name": "province",
"parent": "1"
}
}
PUT map/_doc/5?routing=2&refresh
{
"province.id": "5",
"province.provinceName": "Anhui",
"relationship": {
"name": "province",
"parent": "2"
}
}
PUT map/_doc/6?routing=2&refresh
{
"province.id": "6",
"province.provinceName": "Shanghai",
"relationship": {
"name": "province",
"parent": "2"
}
}
PUT map/_doc/7?routing=2&refresh
{
"city.id": "7",
"city.cityName": "suzhou",
"city.attractions":"huangcangyu",
"relationship": {
"name": "city",
"parent": "5"
}
}
PUT map/_doc/8?routing=2&refresh
{
"city.id": "8",
"city.cityName": "maanshan",
"city.attractions":"caishiji",
"relationship": {
"name": "city",
"parent": "5"
}
}
查询DSL:</p>
GET /map/_search
{
"query": {
"has_child": {
"type": "province",
"query": {
"has_child": {
"type": "city",
"query": {
"match": {
"city.cityName": "maanshan"
}
}
}
}
}
}
}
上面的查询 DSL 没有结果:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
解决方案
推荐阅读
- javascript - 将变量传递给函数: var image = dymo.label.framework.loadImageAsPngBase64(variable);
- python - 在 MS COCO 上训练 Deeplab
- python - Python 列表作为列表索引
- javascript - 在 Angular 中同步 Ajax 调用
- c# - 当没有 x86 时,针对“AMD64”的 dll 与项目的目标平台“x86”不兼容
- python - 什么是使元组列表中的元素在python中唯一的有效方法?
- javascript - 分类数据的 Mapbox 数据驱动样式 - 如何将表达式与数组输入匹配?
- django - 如何在 Django views.py 的查询集中将持续时间或字符串转换为整数?
- c++ - 如何从文件读取数据到向量?
- c# - 将数据表转换为 Google 图表数据表