分页的Elasticsearch From和Size on aggregation

时间:2018-05-15 17:13:48

标签: elasticsearch elasticsearch-aggregation elasticsearch-dsl elasticsearch-dsl-py

首先,我想说我想要实现的要求在SOLR 5.3.1上运行得很好,但在AWS上作为服务的ElasticSearch 6.2却没有。

我的实际查询非常庞大且复杂,它在kibana上工作正常,但是当我越过从= 100 size = 50 时它没有显示错误在kibana控制台上,

我所知道的:

对于普通搜索,最大来自可以 10000 和  对于汇总搜索,最大来自可以 100

如果我越过了这个限制,那么我就要更改最大限制这是不可能的,因为我在AWS上使用ES作为服务或我已经使用使用滚动ID功能滚动 API以获取分页数据。

Scroll API工作得很好,因为我已经将它用于我项目的另一部分但是当我尝试使用聚合的相同Scroll时,它无法按预期工作。

此处使用Scroll API,第一次搜索获取聚合数据,但第二次使用滚动ID调用不返回仅显示命中结果的聚合结果

查询Kibana

GET /properties/_search
{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "published": true
          }
        },
        {
          "match": {
            "country": "South Africa"
          }
        }
      ]
    }
  },
  "aggs": {
    "aggs_by_feed": {
      "terms": {
        "field": "feed",
        "order": {
          "_key": "desc"
        }
      },
      "aggs": {
        "tops": {
          "top_hits": {
            from: 100,
            size: 50,
            "_source": [
              "id",
              "feed_provider_id"
            ]
          }
        }
      }
    }
  },
  "sort": [
    {
      "instant_book": {
        "order": "desc"
      }
    }
  ]
}

使用搜索python:我遇到的问题搜索,首次搜索获得聚合数据使用 Hits 数据但是对于使用滚动ID的下一次调用,它不会返回仅显示 Hits 数据的聚合数据。

if index_name is not None and doc_type is not None and body is not None:
   es = init_es()
   page = es.search(index_name,doc_type,scroll = '30s',size = 10, body = body)
   sid = page['_scroll_id']
   scroll_size = page['hits']['total']

   # Start scrolling
   while (scroll_size > 0):

       print("Scrolling...")
       page = es.scroll(scroll_id=sid, scroll='30s')
       # Update the scroll ID
       sid = page['_scroll_id']

       print("scroll id: " + sid)

       # Get the number of results that we returned in the last scroll
       scroll_size = len(page['hits']['hits'])
       print("scroll size: " + str(scroll_size))

       print("scrolled data :" )
       print(page['aggregations'])

在python上使用Elasticsearch-DSL:通过这种方法,我很难选择_source字段名称,如idfeed_provider_id第二个aggs ig tops-> top_hits

es = init_es()
    s = Search(using=es, index=index_name,doc_type=doc_type)

    s.aggs.bucket('aggs_by_feed', 'terms', field='feed').metric('top','top_hits',field = 'id')
    response = s.execute()
    print('Hit........')
    for hit in response:
        print(hit.meta.score, hit.feed)
    print(response.aggregations.aggs_by_feed)
    print('AGG........')
    for tag in response.aggregations.aggs_by_feed:
        print(tag)

所以我的问题是

是否无法使用来自尺寸字段为上面的聚合查询从= 100获取数据?

如果有可能,那么请给我一个正常 elasticsearch 方式或 elasticsearch-dsl python方式的提示,因为我对elasticsearch-dsl和elasticsearch bucket并不熟悉,matric等。

关于SO的一些答案被告知要使用分区,但我不知道如何在我的方案中使用它How to control the elasticsearch aggregation results with From / Size?

其他人说ES目前不支持此功能(目前正在使用功能请求)。如果那不可能,还可以用什么来代替Solr中的分组?

0 个答案:

没有答案