Elasticsearch 查询:匹配句子数组中的单词

Elasticsearch query: match word in array of sentences

我有一个字段,它是一个句子数组(字符串)。如果单词在句子中,我想在数组中搜索。

"fields": {
           "title": [
              "The book of the world"
           ]
        }

简单查询 "book" 没有 return 预期结果:

GET catalog/_search
  {
    "fields" : "title",
    "query":{
       "match" : {
          "title":"book"
       }
     }
}

你有想法吗?

您必须在将数据添加到索引之前配置分析器。

分析器是 "split" 你的句子作为标记的东西(这里:"the" "book" "of" "the" "world" 或删除停用词 "book" "world").

请阅读 https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-analyzers.html

上的文档

还要注意Elasticsearch是如何处理数组的:https://www.elastic.co/guide/en/elasticsearch/reference/current/array.html

这种情况下的字段名称是 fields.title 而不是标题。

尝试:

GET catalog/_search
{
    "fields" : "fields.title",
    "query":{
       "match" : {
          "fields.title":"book"
       }
     } 
}