带有function_score的ElasticSearch aggs

时间:2018-07-05 08:03:17

标签: elasticsearch elasticsearch-aggregation

我试图排除重复的文档,这些文档具有相同的java.lang.NullPointerException at java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469) at java.util.TimSort.binarySort(TimSort.java:296) at java.util.TimSort.sort(TimSort.java:221) at java.util.Arrays.sort(Arrays.java:1438) at java.util.Arrays$ArrayList.sort(Arrays.java:3895) at java.util.Collections.sort(Collections.java:175) 参数,因此我在ElasticSearch(版本2.4)中使用 aggs 。我使用-此查询:

slug

运行时出现错误

  

无法解析搜索源。预期的字段名称,但获得了[START_OBJECT]   我不知道哪里出了错。

没有 aggs 部分,一切正常(当前重复项除外)

1 个答案:

答案 0 :(得分:0)

我看到一个与以下事实有关的问题:在源过滤部分include中应读为includes。另外,aggs部分不在正确的位置,您将其放在查询部分中,并且应该位于顶层:

{
  "fields": [
    "id",
    "score"
  ],
  "size": 0,
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "main_headline.en": {
                  "query": "headline_for_search"
                }
              }
            },
            {
              "match": {
                "body.en": "body for search"
              }
            }
          ],
          "must_not": {
            "term": {
              "id": 75333
            }
          },
          "filter": [
            {
              "term": {
                "status": 3
              }
            },
            [
              {
                "term": {
                  "sites": 6
                }
              }
            ]
          ]
        }
      },
      "functions": [
        {
          "gauss": {
            "published_at": {
              "scale": "140w",
              "decay": 0.3
            }
          }
        }
      ]
    }
  },
  "aggs": {
    "postslug": {
      "terms": {
        "field": "slug",
        "order": {
          "top_score": "desc"
        }
      },
      "aggs": {
        "grouppost": {
          "top_hits": {
            "_source": {
              "includes": [
                "id",
                "slug"
              ]
            },
            "size": 10
          }
        }
      }
    }
  }
}