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

查看:27
本文介绍了在 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]];

我尝试将字典的 "analysis" 分支放在几个地方(在映射内等),但无济于事.我想一个完整的例子(我现在找不到)也会帮助我.可能我遗漏了一些相当基本的东西.

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天全站免登陆