弹性搜索双面 [英] elastic search double facet

查看:165
本文介绍了弹性搜索双面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个弹性搜索查询,它通过两个不同字段(纬度和经度)的组合对数据进行分组。

 卷曲-XGET http://www.my_server:9200 / idx_occurrence / Occurrence / _search?pretty = true -d'{
query:{
query_string:{
fields :[genus_interpreted,dataset],
query:Pica 2,
default_operator:AND
}
},
facet:{
test:{
terms:{
fields:[decimalLatitude,decimalLongitude],
size 500000000
}
}
}
}'

它的结果比预期的多了两个...任何想法?



答案的相关部分越多...

  _shards:{
total:5,
success:5,
failed b $ b},
嗨ts:{
total:** 37 **,
max_score:3.9314494,
hits:[{
/ pre>

总匹配,37是查询的结果,如果我不应用方面。这个总数是面积的一半(见下文)

 facets:{
test :{
_type:terms,
missing:0,
total:** 74 **,
other:0,
条款:[
{term:167.21665954589844,count:5},
{term:167.25,count:4},
{term:167.14999389648438,count:4},
{term:167.1041717529297,count:4},
{term: - 21.04166603088379 ,count:4},.....

所以,facet分组是完整的(按纬度,然后是经度)。



请注意,我不能仅通过纬度或经度进行分组,因为多个记录可以分享纬度(但具有不同的经度)或反之亦然

解决方案

您正在多个字段上制作一个TermsFacet:纬度和经度。这意味着纬度和经度会聚集在一起,因为它们是一个独特的领域。您可以看到每个单个值的条目,可以是纬度或经度。事实上,您获得了74个条目,证明您的索引中有74个不同的纬度和经度值,这是有道理的。你想要达到什么?每个纬度对的一个面条目?在这种情况下,您有两个选项:




  • 在索引中添加一个附加字段,其中包含对本身,然后在其上面加上

  • 使用术语脚本即时创建纬度经向对。查看文档了解更多信息。这是一个应该有帮助的例子,试一试:




  {
query:{
match_all:{}
},
facets:{
tags:{
terms:{
field:latitude,
script:term + \_\+ _source.longitude
}
}
}
}



I want to run an elastic search query which groups data by the combination of two different fields (Latitude and Longitude)

curl -XGET http://www.my_server:9200/idx_occurrence/Occurrence/_search?pretty=true -d '{  
    "query": { 
        "query_string" : { 
            "fields" : ["genus_interpreted","dataset"], 
            "query": "Pica 2", 
            "default_operator" : "AND" 
         } 
    }, 
    "facets": { 
        "test": { 
            "terms": { 
                "fields" :["decimalLatitude","decimalLongitude"],
                "size" : 500000000 
            } 
        } 
    } 
}'

It gives a double number of results than expected... any idea?

The more relevants parts of the answer are...

_shards":{
    "total":5,
    "successful":5,
    "failed":0
},
"hits":{
    "total":**37**,
    "max_score":3.9314494,
    "hits":[{

the total hits, 37 is the result of the query if I don't apply the facets. This total is the half of the total in facets (see below)

"facets":{
    "test":{
        "_type":"terms",
        "missing":0,
        "total":**74**,
        "other":0,
        "terms":[
           {"term":"167.21665954589844","count":5},
           {"term":"167.25","count":4},
           {"term":"167.14999389648438","count":4},
           {"term":"167.1041717529297","count":4},
           {"term":"-21.04166603088379","count":4},.....

So, the facet grouping is done separetely (by latitude and then by longitude).

Please notice that I cannot group only by latitude or longitude, as multiple records can share latitude (but have different longitude) or viceversa.

解决方案

You are making a TermsFacet on multiple fields: latitude and longitude. That means that latitude and longitude are aggregated together as they were an unique field. You see an entry for each single value, which can be either a latitude or a longitude. The fact that you get 74 entries back proves that you have 74 distinct latitude and longitude values in your index, which makes sense. What do you want to achieve exactly? One facet entry for each latitude longitude pair? In that case you have two options:

  • Add an additional field to the index which contains the pair itself and then facet on it
  • Create the latitue longitude pair on the fly using a term script. Have a look at the documentation to know more. Here is an example that should help, give it a try:

{
    "query" : {
        "match_all" : { }
    },
    "facets" : {
        "tags" : { 
            "terms" : {
                "field" : "latitude",
                "script" : "term + \"_\" + _source.longitude"
            }
        }
    }
}

这篇关于弹性搜索双面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆