使用映射和设置创建索引时未发现分析器异常
嗨,我正在使用Elastic Search
elasticsearch-0.90.2版本。我正在尝试使用jsonBuilder使用自定义分析器来映射分析器,同时创建索引时,它会抛出未找到分析器的异常。
设置 :-
XContentBuilder settings = XContentFactory.jsonBuilder() .startObject()
.startObject("settings")
.startObject("analysis")
.startObject("analyzer")
.startObject("search_analyzer")
.field("tokenizer", "ngram_specification")
.field("type", "custom")
.field("filter", new String[]{ "ngram_specification"})
.endObject()
.endObject()
.startObject("ngram_specification")
.field("type", "nGram")
.field("min_gram", "2")
.field("max_gram", "5")
.endObject()
.endObject()
.endObject()
.endObject();
映射:-
XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject()
.startObject("sample")
.startObject("properties")
.startObject("email").field("type", "string").field("index", "analyzed").field("analyzer", "search_analyzer")
.endObject()
.endObject()
.endObject()
.endObject();
像这样创建索引:
CreateIndexRequest indexRequest = new CreateIndexRequest(indexName); indexRequest.settings(settings);
indexRequest.mapping("sample", mapping);
CreateIndexResponse response = client.admin().indices().create(indexRequest).actionGet();
例外情况:
17:00:52,767 ERROR [STDERR] org.elasticsearch.index.mapper.MapperParsingException: mapping [3] 17:00:52,767 ERROR [STDERR] at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:289)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:229)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:95)
17:00:52,767 ERROR [STDERR] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
17:00:52,767 ERROR [STDERR] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
17:00:52,767 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)
17:00:52,767 ERROR [STDERR] Caused by: org.elasticsearch.index.mapper.MapperParsingException: Analyzer [search_analyzer] not found for field [email]
17:00:52,767 ERROR [STDERR] at org.elasticsearch.index.mapper.core.TypeParsers.parseField(TypeParsers.java:100)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.index.mapper.core.StringFieldMapper$TypeParser.parse(StringFieldMapper.java:151)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseProperties(ObjectMapper.java:263)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(ObjectMapper.java:219)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:176)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:380)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.index.mapper.MapperService.merge(MapperService.java:190)
17:00:52,767 ERROR [STDERR] at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:286)]
任何人都可以告诉这种方法中的错误吗?
回答:
我找到了解决方案。在“设置”中,如果您使用“索引”而不是“设置”,那么它将正常工作。
这是错误的:
XContentBuilder settings = XContentFactory.jsonBuilder() .startObject()
.startObject("settings") // "settings"
.startObject("analysis")
但是这样 做 :
XContentBuilder settings = XContentFactory.jsonBuilder() .startObject()
.startObject("index") // "index" instead of "settings"
.startObject("analysis")
以上是 使用映射和设置创建索引时未发现分析器异常 的全部内容, 来源链接: utcz.com/qa/409643.html