elasticsearch - 如何知道哪些关键字在elasticsearch中匹配

标签 elasticsearch lucene text-mining nosql

假设我查询:

POST /story/story/_search
{  
   "query":{  
      "bool":{  
         "should":[  
            {  
               "match":{  
                  "termVariations":{  
                     "query":"not driving",
                     "type":"boolean",
                     "operator":"AND"
                  }
               }
            },
            {  
               "match":{  
                  "termVariations":{  
                     "query":"driving",
                     "type":"boolean",
                     "operator":"AND"
                  }
               }
            }
         ]
      }
   }
}

此查询由一个分析器或另外 3 个文档返回。 我如何判断哪个 should 子句被匹配? Elasticsearch 可以随结果一起返回匹配的短语吗?

谢谢!

最佳答案

这里最好的选择是 named queries 。 您可以为查询命名,并且每个文档都会提供匹配的查询的名称。

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name.first": {
              "query": "qbox",
              "_name": "first"
            }
          }
        },
        {
          "match": {
            "name.last": {
              "query": "search",
              "_name": "last"
            }
          }
        }
      ]
    }
  }
}

关于elasticsearch - 如何知道哪些关键字在elasticsearch中匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33674787/

相关文章:

database - 文本情感检测数据集

python - 从列表列表中删除用户名

search - 设置solr搜索词所需字符

lucene - 空查询 - 更像这样(Lucene)

scikit-learn - 使用随机森林时在 scikit-learn 中表示因子变量的方法是什么?

elasticsearch - FileBeat收集问题

elasticsearch - 在Kubernetes中部署Elk堆栈,并带有 Helm VolumeBinding错误

r - 如何在 R 中对 Elasticsearch 执行 GET 请求

java - 如何在 SearchResponse 中使用 elasticSearch java api 访问聚合结果?

indexing - 如何在 GUI 中获取 Hibernate Lucene 索引创建的统计信息?