【问题标题】:elastic search double facet弹性搜索双面
【发布时间】:2012-08-31 08:38:28
【问题描述】:

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

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

它给出的结果是预期的两倍……有什么想法吗?

答案中更相关的部分是......

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

总命中数,如果我不应用构面,则查询结果为 37。这个总数是方面总数的一半(见下文)

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

因此,分面分组是单独完成的(按纬度,然后按经度)。

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

【问题讨论】:

  • 你能显示你得到的输出吗?
  • 我不能接受我认为不能真正解决问题的答案...

标签: lucene elasticsearch


【解决方案1】:

您正在多个字段上创建一个术语方面:纬度和经度。这意味着纬度和经度被聚合在一起,因为它们是一个独特的字段。您会看到每个单个值的条目,可以是纬度或经度。您返回 74 个条目的事实证明您的索引中有 74 个不同的纬度和经度值,这是有道理的。你到底想达到什么目的?每个纬度经度对的一个方面条目?在这种情况下,您有两种选择:

  • 向索引中添加一个附加字段,该字段包含该对本身,然后对其进行构面
  • 使用术语脚本即时创建纬度经度对。查看documentation 了解更多信息。这是一个应该有所帮助的示例,请尝试一下:
{
    "query" : {
        "match_all" : { }
    },
    "facets" : {
        "tags" : { 
            "terms" : {
                "field" : "latitude",
                "script" : "term + \"_\" + _source.longitude"
            }
        }
    }
}

【讨论】:

  • 我想实现对共享完全相同位置(相同纬度和经度)的所有数据进行精确分组。现在添加一个新字段有点复杂,所以我想动态连接纬度和经度,使用它进行分组。一个方面,例如... "terms": { "fields" :["decimalLatitude","decimalLongitude"],"script":"term[1]","size" : 500 个作品,将 term[1] 引用到 decimalLongitude ,但根本不是我需要的。事实上,即使我可以加入 term[0] term[1],这也无法与 index 上的任何内容进行比较,所以根本无法弄清楚如何获得它......
猜你喜欢
  • 2021-11-23
  • 2017-04-24
  • 1970-01-01
  • 2012-02-12
  • 2018-10-26
  • 1970-01-01
  • 1970-01-01
  • 2022-07-07
  • 2013-11-25
相关资源
最近更新 更多