索引过滤器未返回预期结果的ElasticSearch术语_enum

3z6pesqy  于 2022-09-20  发布在  ElasticSearch
关注(0)|答案(1)|浏览(170)

我们在Elastic Search中有一个索引(Newblog),其中包含以下记录:

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "newblog",
        "_id": "arer2121",
        "_score": 1,
        "_source": {
          "id": "arer2121",
          "title": "Python 101 Elasticsearch",
          "author": "John Doe",
          "rating": 3,
          "time": 1662012000000,
          "keywords": [
            "java",
            "python"
          ]
        }
      },
      {
        "_index": "newblog",
        "_id": "spb111",
        "_score": 1,
        "_source": {
          "id": "spb111",
          "title": "Spring boot 101 tuto",
          "author": "Jeff Green",
          "rating": 2,
          "time": 1614585600000,
          "keywords": [
            "java",
            "python",
            "spring boot"
          ]
        }
      },
      {
        "_index": "newblog",
        "_id": "gjv12121",
        "_score": 1,
        "_source": {
          "id": "gjv12121",
          "title": "Java 101 tuto",
          "author": "Anthony Davis",
          "rating": 1,
          "time": 1577869200000,
          "keywords": [
            "java"
          ]
        }
      }
    ]
  }
}

我们正在尝试使用以下查询从索引中提取特定记录:

GET newblog/_terms_enum
{
  "field":"keywords.keyword",
  "string":"",
  "case_insensitive": true,
  "index_filter":
  {
    "match": {
      "title.keyword": {
        "query": "Spring boot"
      }
    }
  }
}

在这个查询中,我们预计只会显示‘Spring boot101 tuto’,但是当我们运行这个查询时,它将获取所有三条记录。如果我们不使用INDEX_FILTER,那么查询只给出特定的记录,但我们的用例是首先查看所有关键字--Java、PYTHON、SPUNG,然后从它过滤Spring引导。

我们使用的是弹性8.3.2。

46scxncf

46scxncf1#

遗憾的是,INDEX_FILTERWITHTERMS_ENUM没有给出预期的结果,但是我们可以通过搜索和聚合得到结果。

GET blog/_search
{
  "query": {
    "match_phrase": {
      "title": "Spring boot"
    }
  }, 
  "size":0,
  "aggs": {
    "keywords": {
      "terms": { "field": "keywords" }
    }
  }
}

参考链接:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

相关问题