Sunday, 7 May 2017

ElasticSearch - Aggregation/Group by: sorting and pagging

I'm trying to use Elasticsearch aggregation to group by "productId" on more then one index using that query

{
  "from": 0,
  "size": 0,
  "min_score": 0.15,
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "match_phrase_prefix": {
                "keywords.family": {
                  "query": "low fat milk",
                  "fuzziness": 0.7,
                  "boost": 5
                }
              }
            }
          ]
        }
      }
    }
  },
  "aggs": {
    "group_by_0": {
      "terms": {
        "field": "productId",
        "size": 50

      },
      "aggs": {
        "top_tag_hits": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  }
}

1) I want to sort by _score so I've tried using

"order": {"_score": "desc"}

which return

"type": "aggregation_execution_exception",
"reason": "Invalid term-aggregator order path [_score]. Unknown aggregation [_score]"

2) Also, I'm trying to use paging - the "size" key actually working but "from" won't

Hope someone can help



via Beni Gazala

No comments:

Post a Comment