Elasticsearch index creation keeps looking for "_doc"
See original GitHub issueSpringBoot 2.4.1 Spring Data Elasticsearch 4.1.2
Bug:
I am trying to create the mapping for my index, through the following code:
@Override
public Mono<Boolean> createIndex() {
var request = new CreateIndexRequest(getIndex());
request.source(getMappingSource(), getXContentType());
return reactiveElasticsearchClient.indices()
.createIndex(request)
.doOnSuccess(success ->
log.info("Index Creation \"{}\": {}", getIndex(), success));
}
and this mapping:
public static final String DEFAULT_ES_MAPPING_SOURCE =
"{\n" +
" \"mappings\": {\n" +
" \"properties\": {\n" +
" \"timestamp\": {\n" +
" \"type\": \"date\",\n" +
" \"format\": \"epoch_millis||yyyy-MM-dd HH:mm:ss||yyyy-MM-dd\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";
This error comes out: org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=mapper_parsing_exception, reason=Failed to parse mapping [_doc]: No type specified for field [properties]], Elasticsearch exception [type=mapper_parsing_exception, reason=No type specified for field [properties]]
If I add the “_doc” before “properties” in the mapping JSON (as the previous exception asked me), I get another error (non-sense): org.elasticsearch.ElasticsearchStatusException: Elasticsearch exception [type=illegal_argument_exception, reason=The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true.], Elasticsearch exception [type=illegal_argument_exception, reason=The mapping definition cannot be nested under a type [_doc] unless include_type_name is set to true.]
Could you please fix it?
EDIT:
I have found an answer (https://github.com/elastic/elasticsearch/issues/40897#issuecomment-480833056) that shows that your class (ReactiveElasticsearchClient) accepts the wrong CreateIndexRequest.
org.elasticsearch.action.admin.indices.create.CreateIndexRequest is compatible with ES 6.x org.elasticsearch.client.indices.CreateIndexRequest is compatible with ES 7.x [BUT I cannot use it since the client accepts the other]
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
There is
org.springframework.data.elasticsearch.core.ReactiveIndexOperations#create()
andorg.springframework.data.elasticsearch.core.ReactiveIndexOperations#putMapping()
and these functions definitely work.But we should indeed use the same
CreateIndexRequest
as we do in the non-reactive code. The same for theGetIndexRequest
,PutMappingRequest
andGetMappingRequest
. I created #1658 to address that.ReactiveIndexOperations
has methods for creating indices, writing mappings and settings. What is missing in these methods that you implement your owncreateIndex()
? Is this in a customReactiveIndexOperations
implementation?Although the code is using
org.elasticsearch.action.admin.indices.create.CreateIndexRequest
it’s working up to the actual Elasticsearch version 7.10.2.