elasticsearch6.5.0 创建索引报错mapper_parsing_exception

发布于 2022-09-12 00:13:32 字数 10241 浏览 12 评论 0

问题描述

spring boot集成elasticsearch-rest-high-level-client 6.5.0,创建index时候报错 mapper_parsing_exception

问题出现的环境背景及自己尝试过哪些方法

最近在学习springboot整合es,试过springboot集成的es,但是说transportclient已经要废弃,就想着使用elasticsearch-rest-high-level-client,创建 index第一步就卡住了。 createIndexRequest.mapping()这个方法试过传形参 map类型的,也试过传递XContentBuilder这种类型的都不可以。

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class DemoTest {

@Autowired
private RestHighLevelClient restHighLevelClient;

// 创建索引
@Test
public void createIndex() throws IOException {
// 创建索引的名称
CreateIndexRequest createIndexRequest = new CreateIndexRequest("books");
createIndexRequest.settings(Settings.builder().put("number_of_shards", 1).put("number_of_replicas", 0));
// 创建索引的setting (包含分片 ,备份之类的)
// 设置mapping
XContentBuilder builder = JsonXContent.contentBuilder()
.startObject()
.startObject("mappings")
.startObject("books")
.startObject("properties")
.startObject("title")
.field("type", "text")
.endObject()
.startObject("content")
.field("type", "text")
.endObject()
.startObject("uniqueId")
.field("type", "keyword")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject();
// String s = XContentHelper.convertToJson(BytesReference.bytes(builder), false, false, XContentType.JSON);
// System.out.println(s);
createIndexRequest.mapping("books", builder);
restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);

}

}

你期待的结果是什么?实际看到的错误信息又是什么?

实际执行的时候报错:
ElasticsearchStatusException[Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [books]: Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]]
]; nested: ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]]];

at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177)
at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1793)
at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1769)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1606)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1563)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1525)
at org.elasticsearch.client.IndicesClient.create(IndicesClient.java:146)
at com.example.elasticsearchdemo2.DemoTest.createIndex(DemoTest.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Suppressed: org.elasticsearch.client.ResponseException: method [PUT], host [http://172.16.28.55:9200], URI [/books?master_timeout=30s&timeout=30s], status line [HTTP/1.1 400 Bad Request]

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [books]: Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]"}},"status":400}

    at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:936)
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:233)
    at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1593)
    ... 34 more
Caused by: org.elasticsearch.client.ResponseException: method [PUT], host [http://172.16.28.55:9200], URI [/books?master_timeout=30s&timeout=30s], status line [HTTP/1.1 400 Bad Request]

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [books]: Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]"}},"status":400}

    at org.elasticsearch.client.RestClient$1.completed(RestClient.java:552)
    at org.elasticsearch.client.RestClient$1.completed(RestClient.java:537)
    at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:122)
    at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.responseCompleted(DefaultClientExchangeHandlerImpl.java:181)
    at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:448)
    at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:338)
    at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:265)
    at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:81)
    at org.apache.http.impl.nio.client.InternalIODispatch.onInputReady(InternalIODispatch.java:39)
    at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:114)
    at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
    at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
    at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:591)
    at java.lang.Thread.run(Thread.java:745)

Caused by: ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=Root mapping definition has unsupported parameters: [mappings : {books={properties={title={type=text}, content={type=text}, uniqueId={type=keyword}}}}]]]

at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:509)
at org.elasticsearch.ElasticsearchException.fromXContent(ElasticsearchException.java:420)
at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:450)
at org.elasticsearch.ElasticsearchException.failureFromXContent(ElasticsearchException.java:616)
at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:169)
... 37 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文