在弹性搜索中映射geo点类型的嵌套字段

时间:2015-02-03 11:57:28

标签: php elasticsearch

获取映射API让我注意到了这个问题。我不知道究竟是什么问题,但我将解释这个场景

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

    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
    

1 个答案:

答案 0 :(得分:1)

您需要在嵌套映射定义中将"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"}
                    }
                }
            }
        }
    }
}

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