1

我正在尝试将弹性搜索索引配置为使用keyword分析器进行分析的默认索引策略,然后在某些字段上覆盖它,以允许对它们进行自由文本分析。如此有效地选择加入自由文本分析,我在映射中明确指定分析哪些字段以进行自由文本匹配。我的映射定义如下所示:

PUT test_index
{
   "mappings":{
      "test_type":{
         "index_analyzer":"keyword",
         "search_analyzer":"standard",
         "properties":{
            "standard":{
               "type":"string",
               "index_analyzer":"standard"
            },
            "keyword":{
               "type":"string"
            }
         }
      }
   }
}

所以standard应该是一个分析的字段,并且keyword应该是完全匹配的。但是,当我使用以下命令插入一些示例数据时:

POST test_index/test_type
{
  "standard":"a dog in a rug",
  "keyword":"sheepdog"
}

我没有得到与以下查询的任何匹配:

GET test_index/test_type/_search?q=dog

但是我确实得到了比赛:

GET test_index/test_type/_search?q=*dog*

这让我觉得这个standard领域没有被分析。有谁知道我做错了什么?

4

1 回答 1

2

创建的索引没有问题。将您的查询更改为GET test_index/test_type/_search?q=standard:dog,它应该返回预期的结果。

如果您不想在查询中指定字段名称,请更新您的映射,以便为每个字段显式提供index_analyzersearch_analyzer值,而无需默认值。见下文:

PUT test_index
{
   "mappings": {
      "test_type": {
         "properties": {
            "standard": {
               "type": "string",
               "index_analyzer": "standard",
               "search_analyzer": "standard"
            },
            "keyword": {
               "type": "string",
               "index_analyzer": "keyword",
               "search_analyzer": "standard"
            }
         }
      }
   }
}

现在,如果你尝试GET test_index/test_type/_search?q=dog,你会得到想要的结果。

于 2015-03-30T15:15:50.293 回答