Elasticsearch,距离字段不显示在结果中

时间:2016-01-18 01:16:20

标签: elasticsearch

我已使用此手动创建此映射:

    $ curl -X PUT 'http://localhost:9200/location_index' -d '{
        "mappings" : {
            "nodes" : {
                "dynamic": true, 
                "properties" : {
                    "id" : {
                        "type" : "long"
                    },
                    "idx" : {
                        "type" : "string"
                    },
                    "idx2" : {
                        "type" : "string"
                    },
                    "location" : {
                        "type" : "geo_point"
                    },
                    "name" : {
                        "type" : "string"
                    },
                    "address_full" : {
                        "type" : "string"
                    },
                    "tags" : {
                        "properties" : {
                            "name" : {
                                "type" : "string"
                            },
                            "slug" : {
                                "type" : "string"
                            }
                        }
                    }
                }
            }
        }
    }'

我有这个查询:

{  
    "query":{  
        "filtered":{  
            "filter":{  
                "geo_distance":{  
                    "distance":"20km",
                    "location":{  
                        "lat":40.728199,
                        "lon":-74.077599
                    }
                }
            }
        }
    },
    "script_fields":{  
        "distance":{  
            "lang":"groovy",
            "params":{  
                "lat":40.728199,
                "lon":-74.077599
            },
            "script":"doc['location'].distanceInKm(lat,lon)"
        }
    },
    "sort":[  
        {  
            "_geo_distance":{  
                "location":{  
                    "lat":40.728199,
                    "lon":-74.077599
                },
                "order":"asc",
                "unit":"km",
                "mode":"min",
                "distance_type":"plane"
            }
        }
    ],
    "fields":[  
        "_source",
        "distance"
    ]
}

我的问题是我没有将结果中的距离作为一个字段。所以我也不知道结果是否按距离排序。

有什么想法吗?这可能是一个让我无法做到的动态"动态"字段?

如果是这样,我的elasticsearch.yaml是这样的:

   node.name: "My First Node"
   cluster.name: mycluster1
   node.data: true
   index.number_of_shards: 1
   index.number_of_replicas: 0
   network.bind_host: localhost
   script.inline: on
   script.indexed: on

0 个答案:

没有答案