使用模糊滤波器进行聚合

时间:2017-01-24 20:56:27

标签: elasticsearch

Elastisearch中是否有可能有一个包含模糊的过滤器/查询的聚合?

ATM我有包含嵌套对象[]的文档。我想要实现的目标:

- select from each document 0..n nested objects which match a filter
- from this array of nested objects take the distinct one
- sort them by _score
- take the top 5 or X
- use the terms for an autocomplete/suggestions (should work more as a "like" and not autocomplete)

到目前为止,我尝试了不同类型的聚合,例如:significant_terms,top_hits但没有很好的组合,所以我没有得到理想的结果。 问题:

  1. significant_terms不会返回一个值,直到他找出一个术语很重要的时候(也许我没有使用好的分析器)
  2. top-hits从所选文档返回任何嵌套的obj,并且还包含重复项
  3. 以下是我的查询示例

      GET customerinsights/_search
    
        {
      "query": {
        "bool": {
          "must": [
            {
              "nested": {
                "path": "CustomerInsightTargets",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "match": {
                          "CustomerInsightTargets.CustomerInsightValue": {
                            "query": "2017",
                            "operator": "AND",
                            "fuzziness": 2
                          }
                        }
                      }
                    ]
                  }
                }
    
              }
            }
          ]
        }
      } ,
      "aggs": {
        "root": {
          "nested": {
            "path": "CustomerInsightTargets"
          },
          "aggs": {
            "top_tags": {
              "terms": {
                "field": "CustomerInsightTargets.CustomerInsightSource.keyword"
              },
              "aggs": {
                "top_tag_hits": {
                  "top_hits": {
                    "sort": [
                      {
                        "_score": {
                          "order": "desc"
                        }
                      }
                    ],
                    "size": 5,
                    "_source": "CustomerInsightTargets"
                  }
                }
              }
            }
          }
        }
      },
      "size": 0,
      "_source": "CustomerInsightTargets"
    }
    

0 个答案:

没有答案