弹性搜索中地理点类型嵌套字段的映射
Mapping for nested fields of type geo point in elastic search
获取映射 API 让我注意到了这个问题。我不知道到底是什么问题,但我会解释一下情况
- 将根级别字段的映射定义为地理点。
- 获取相同字段的映射会产生预期的输出。
- 将嵌套字段的映射定义为地理点。
- 对嵌套字段使用 get 映射 API 在索引 0 个文档的情况下没有结果,returns 在索引中至少有一个文档的情况下使用字符串类型。
…………
映射
…………
`
PUT /loc_index_nw
{
"mappings": {
"loc_data_nw": {
"properties": {
"primary_name_nw": {"type": "string"},
"location_nw": {"type": "geo_point"},
"id_nw": {"type": "string"},
"locality_nw": {"type" : "string"},
"fav_locations": {
"type": "nested",
"fields": {
"nested_locality_nw": {"type": "geo_point"},
"nested_location_type": {"type": "string"}
}
}
}
}
}
}
`
…………
在索引任何文档之前获取映射(仅获取特定字段的映射)
.........
GET loc_index_nw/_mapping/loc_data_nw/field/fav_locations.nested_location_type,fav_locations.nested_locality_nw
…………
样本数据
…………
`
POST /loc_index_nw/loc_data_nw/1
{
"id_nw":1,
"primary_name_nw":"National Sarvodaya School",
"location_nw":{"lat":"19.046304","lon":"72.897536"},
"locality_nw":"chembur",
"fav_locations":[
{
"nested_location_type": "office",
"nested_locality_nw": {"lat":"19.04","lon": "72.89"}
},
{
"nested_location_type": "home",
"nested_locality_nw": {"lat":"19.99","lon": "72.01"}
}
]
}
`
`
POST /loc_index_nw/loc_data_nw/2
{
"id_nw":2,
"primary_name_nw":"Diamond Garden",
"location_nw":{"lat":"19.053493","lon":"72.899992"},
"locality_nw":"chembur",
"fav_locations":[
{
"nested_location_type": "park",
"nested_locality_nw": {"lat":"19.04","lon": "72.89"}
},
{
"nested_location_type": "home",
"nested_locality_nw": {"lat":"19.99","lon": "72.01"}
}
]
}
`
…………
在索引几个文档之前获取映射(仅获取特定字段的映射)
.........
GET loc_index_nw/_mapping/loc_data_nw/field/fav_locations.nested_location_type,fav_locations.nested_locality_nw
您需要在嵌套映射定义中将 "fields"
替换为 "properties"
。所以你的映射应该是这样的:
PUT /loc_index_nw
{
"mappings": {
"loc_data_nw": {
"properties": {
"primary_name_nw": {"type": "string"},
"location_nw": {"type": "geo_point"},
"id_nw": {"type": "string"},
"locality_nw": {"type" : "string"},
"fav_locations": {
"type": "nested",
"properties": {
"nested_locality_nw": {"type": "geo_point"},
"nested_location_type": {"type": "string"}
}
}
}
}
}
}
当我尝试使用您的文档时,效果很好。
获取映射 API 让我注意到了这个问题。我不知道到底是什么问题,但我会解释一下情况
- 将根级别字段的映射定义为地理点。
- 获取相同字段的映射会产生预期的输出。
- 将嵌套字段的映射定义为地理点。
- 对嵌套字段使用 get 映射 API 在索引 0 个文档的情况下没有结果,returns 在索引中至少有一个文档的情况下使用字符串类型。
………… 映射 ………… `
PUT /loc_index_nw
{
"mappings": {
"loc_data_nw": {
"properties": {
"primary_name_nw": {"type": "string"},
"location_nw": {"type": "geo_point"},
"id_nw": {"type": "string"},
"locality_nw": {"type" : "string"},
"fav_locations": {
"type": "nested",
"fields": {
"nested_locality_nw": {"type": "geo_point"},
"nested_location_type": {"type": "string"}
}
}
}
}
}
}
`
………… 在索引任何文档之前获取映射(仅获取特定字段的映射) .........
GET loc_index_nw/_mapping/loc_data_nw/field/fav_locations.nested_location_type,fav_locations.nested_locality_nw
………… 样本数据 ………… `
POST /loc_index_nw/loc_data_nw/1
{
"id_nw":1,
"primary_name_nw":"National Sarvodaya School",
"location_nw":{"lat":"19.046304","lon":"72.897536"},
"locality_nw":"chembur",
"fav_locations":[
{
"nested_location_type": "office",
"nested_locality_nw": {"lat":"19.04","lon": "72.89"}
},
{
"nested_location_type": "home",
"nested_locality_nw": {"lat":"19.99","lon": "72.01"}
}
]
}
`
`
POST /loc_index_nw/loc_data_nw/2
{
"id_nw":2,
"primary_name_nw":"Diamond Garden",
"location_nw":{"lat":"19.053493","lon":"72.899992"},
"locality_nw":"chembur",
"fav_locations":[
{
"nested_location_type": "park",
"nested_locality_nw": {"lat":"19.04","lon": "72.89"}
},
{
"nested_location_type": "home",
"nested_locality_nw": {"lat":"19.99","lon": "72.01"}
}
]
}
`
………… 在索引几个文档之前获取映射(仅获取特定字段的映射) .........
GET loc_index_nw/_mapping/loc_data_nw/field/fav_locations.nested_location_type,fav_locations.nested_locality_nw
您需要在嵌套映射定义中将 "fields"
替换为 "properties"
。所以你的映射应该是这样的:
PUT /loc_index_nw
{
"mappings": {
"loc_data_nw": {
"properties": {
"primary_name_nw": {"type": "string"},
"location_nw": {"type": "geo_point"},
"id_nw": {"type": "string"},
"locality_nw": {"type" : "string"},
"fav_locations": {
"type": "nested",
"properties": {
"nested_locality_nw": {"type": "geo_point"},
"nested_location_type": {"type": "string"}
}
}
}
}
}
}
当我尝试使用您的文档时,效果很好。