Java 创建索引请求映射在弹性搜索中失败
我正在尝试在弹性搜索索引中创建联接数据类型,它正在从kibana控制台/通过rest工作,但当我尝试以编程方式为索引创建映射时,它失败了,出现以下错误Java 创建索引请求映射在弹性搜索中失败,java,
elasticsearch,elasticsearch-7,resthighlevelclient,Java,
elasticsearch,Elasticsearch 7,Resthighlevelclient,我正在尝试在弹性搜索索引中创建联接数据类型,它正在从kibana控制台/通过rest工作,但当我尝试以编程方式为索引创建映射时,它失败了,出现以下错误 java.util.concurrent.ExecutionException: RemoteTransportException[[3cfb4e163654][172.17.0.2:9300][indices:admin/create]]; nested: MapperParsingException[Failed to parse mappi
java.util.concurrent.ExecutionException: RemoteTransportException[[3cfb4e163654][172.17.0.2:9300][indices:admin/create]]; nested: MapperParsingException[Failed to parse mapping [properties]: Root mapping definition has unsupported parameters: [my_join_field : {type=join, relations={question=answer}}] [my_id : {type=keyword}]]; nested: MapperParsingException[Root mapping definition has unsupported parameters: [my_join_field : {type=join, relations={question=answer}}] [my_id : {type=keyword}]];
映射:
{
"properties": {
"my_id": {
"type": "keyword"
},
"my_join_field": {
"type": "join",
"relations": {
"question": "answer"
}
}
}
}
代码:
public void createIndex(ReIndex indexObject) throws XXXDefinedException {
String index = indexObject.getDestinationIndex();
try {
LOG.info("Initiating the index creation process for the " + index);
CreateIndexRequest request = new CreateIndexRequest(index);
if (!CommonUtils.isEmptyMap(indexObject.getMapping())) {
LOG.info("Index Mapping Available : " + index);
String indexMapping = new GsonBuilder().create().toJson(indexObject.getMapping());
request.source(indexMapping, XContentType.JSON);
}
AcknowledgedResponse indexResponse = client.admin().indices().create(request).get();
client.admin().indices().prepareRefresh().execute().actionGet();
LOG.info("Index is created successfully : " + indexResponse);
} catch (Exception e) {
throw new XXXDefinedException (e);
}
}
其中inputObject.getMapping具有以下映射:
{"mappings":{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}}
您的inputObject.getMapping不应包含映射部分。您是否可以在inputObject.getMapping中进行更改,这些更改来自:
{"mappings":{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}}
到
如果可以的话,请告诉我。您还可以添加导入语句吗?看起来indexObject有问题吗?是的,但弹性搜索在内部存储为映射->映射->属性,请检查此链接:因此我使用request.source和{mappings:{mappings:{properties:{my_id:{type:keyword},my_join_字段:{type:join,relations:{question:ans answer}}}}并检查此链接:抱歉,我使用了方法request.mappingjsonString,XContentType.JSON;而不是您使用的,即request.sourcejsonString,XContenType.JSON;。我相信两者都应该足够正确,并且最终会转换为elasticsearch所需的正确JSON格式。如果您阅读CreateRequestIndex的源代码,您将能够看到这两种方法是如何使用的。奇怪的是,我尝试使用源方法和您拥有的映射字符串,但我仍然发现了这个问题。你能更新maven的详细信息吗,只是想检查一下你使用的是什么ES版本。我试过7.7,两次都试过,只有我在回答中提到的JSON有效,但不是你在评论中提到的。你能帮我一下吗
{"properties":{"my_id":{"type":"keyword"},"my_join_field":{"type":"join","relations":{"question":"answer"}}}}