弹性搜索中地理位置点类型的嵌套字段的映射


Mapping for nested fields of type geo point in elastic search

获取映射API让我注意到了这个问题。我不知道问题到底是什么,但我会解释这种情况

  1. 将根级别字段的映射定义为地理点。
  2. 获取相同字段的映射会产生预期输出。
  3. 将嵌套字段的映射定义为地理点。
  4. 对嵌套字段使用 get 映射 API 在索引 0 个文档的情况下不会产生任何结果,如果索引中至少有一个文档,则返回字符串类型。

.........映射.........`

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"}
                    }
                }
            }
        }
    }
}

当我尝试使用您的文档时,它工作正常。