如何从elasticsearch中得到一个没有匹配结果的搜索词列表?

3qpi33ja  于 2023-03-17  发布在  ElasticSearch
关注(0)|答案(1)|浏览(111)

我想统计用户在我的Elasticsearch示例上搜索的词语,但没有返回结果。
这些信息是在Elasticsearch中提供的还是我必须手动跟踪的东西?
例如,

GET /my-index/_search
{
  "query": {
    "query_string": {
      "default_field": "FieldName",
      "analyzer": "standard",
      "query": "TermThatReturnsNoRecords"
    }
  }
}

上面的查询将不返回匹配项,因此我希望能够知道术语TermThatReturnsNoRecords被使用了X次,并且没有返回任何结果。

scyqe7ek

scyqe7ek1#

在elasticsearch中没有现成的功能可以做到这一点,但你需要求助于elasticsearch日志:https://www.elastic.co/guide/en/elasticsearch/reference/current/logging.html
日志包括查询结果的数量,您可以使用这些结果来获取要查找的信息
示例:

{
  "type": "index_search_slowlog",
  "timestamp": "2030-08-30T11:59:37,786+02:00",
  "level": "WARN",
  "component": "i.s.s.query",
  "cluster.name": "distribution_run",
  "node.name": "node-0",
  "message": "[index6][0]",
  "took": "78.4micros",
  "took_millis": "0",
  "total_hits": "0 hits", <--- you can filter by this value
  "stats": "[]",
  "search_type": "QUERY_THEN_FETCH",
  "total_shards": "1",
  "source": "{\"query\":{\"match_all\":{\"boost\":1.0}}}", <--- your query
  "id": "MY_USER_ID",
  "cluster.uuid": "Aq-c-PAeQiK3tfBYtig9Bw",
  "node.id": "D7fUYfnfTLa2D7y-xw6tZg"
}

相关问题