您好我正在使用 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)]
谁能告诉这种方法的错误?