如何在ElasticSearch中创建索引时指定分析器 [英] How to specify an analyzer while creating an index in ElasticSearch

查看:972
本文介绍了如何在ElasticSearch中创建索引时指定分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想指定一个分析器,命名它,并在创建索引时在映射中使用该名称。我失去了,我的ES实例总是给我一个错误消息。

I'd like to specify an analyzer, name it, and use that name in a mapping while creating an index. I'm lost, my ES instance always returns me an error message.

这大概是我想做的:

"settings": {
  "mappings": {
    "alfedoc": {
      "properties": {
        "id": { "type": "string" },
        "alfefield": { "type": "string", "analyzer": "alfeanalyzer" }
      }
    }
  },
  "analysis": {
    "analyzer": {
      "alfeanalyzer": {
        "type": "pattern",
        "pattern":"\\s+"
      }
    }
  }
}

但这似乎不起作用; ES实例总是给我一个错误,如

But this does not seem to work; the ES instance always returns me an error like

MapperParsingException[mapping [alfedoc]]; nested: MapperParsingException[Analyzer [alfeanalyzer] not found for field [alfefield]];

我尝试将分析分支的字典在几个地方(在映射等内),但没有用。我想有一个完整的例子(我到现在为止找不到)也会帮助我。可能我错过了一些相当基本的东西。

I tried putting the "analysis" branch of the dictionary at several places (inside the mapping etc.) but to no avail. I guess a working complete example (which I couldn't find up to now) would help me along as well. Probably I'm missing something rather basic.

推荐答案

分析进入设置块,在创建索引后的映射块之后。

"analysis" goes in the "settings" block, which goes either before or after the "mappings" block when creating an index.

"settings": {
    "analysis": {
        "analyzer": {
            "alfeanalyzer": {
                "type": "pattern",
                "pattern": "\\s+"
            }
        }
    }
},
"mappings": {
    "alfedoc": { ... }
}

这是一个很好的完整的例子:例1

Here's a good complete, example: Example 1

这篇关于如何在ElasticSearch中创建索引时指定分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆