简体   繁体   English

对JSON数据进行ElasticSearch查询

[英]ElasticSearch query on json data

I have json data in format 我有格式的json数据

{"issue_number": 1, "created_at": "2016-03-13", "closed_at": "2016-04-13", "labels": ["Category: Bug", "Latitude:41.925573", "Longitude:-87.649249", "OriginationPhase:Requirements"], "State": "closed"} {“ issue_number”:1,“ created_at”:“ 2016-03-13”,“ closed_at”:“ 2016-04-13”,“ labels”:[“类别:Bug”,“纬度:41.925573”,“经度:-87.649249“,” OriginationPhase:Requires“],” State“:” closed“}

I need to write an elastic search query that retrieves all locations that got atleast 3 issues created for same location ie latitude and longitude. 我需要编写一个弹性搜索查询,以检索为同一位置(即纬度和经度)创建的至少3个问题的所有位置。

To my understanding i need to retrieve the data where issues are more than 3 for same location. 据我了解,我需要检索同一位置问题大于3的数据。 So i need to groupby latitude and longitude , and count should be greater than or equal to 3 所以我需要按纬度和经度分组,并且计数应大于或等于3

I dont have much understanding on elastic search. 我对弹性搜索没有太多了解。 i have referred couple of sites and tried the below code. 我已经提到了几个站点,并尝试了以下代码。

    q = {
    'aggregations':{
                'labels':{
                    'nested':{
                            'path':'labels'
                },
                'aggs':{
                    'latitude':{
                        'terms':{
                                'field':'labels.Latitude',
                                'min_doc_count':3
                            },
                        'aggs':{
                            'by_top_hits':{
                                'top_hits':{
                                    'size':3
                                }
                            }
                        }
                    }
              }

         }
    }
}

But i didn't get the expected result and query doc_count is 0. 但是我没有得到预期的结果,查询doc_count为0。

You are missing a query. 您缺少查询。 In this case, you can start with a Match All Query so that all the documents get evaluated. 在这种情况下,您可以从“ 全部匹配”查询开始,以便评估所有文档。

Regarding you agg query, I don't see the need for the nesting, you can try something like: 关于agg查询,我认为不需要嵌套,您可以尝试执行以下操作:

GET yourindex/_search
{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "locations": {
      "terms": {
        "field":"latitudeNameField"
      }
    }
  },
  "_source": "false"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM