question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Elasticsearch index creation keeps looking for "_doc"

See original GitHub issue

SpringBoot 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:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
sothawocommented, Jan 19, 2021

There is org.springframework.data.elasticsearch.core.ReactiveIndexOperations#create() and org.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 the GetIndexRequest, PutMappingRequest and GetMappingRequest. I created #1658 to address that.

1reaction
sothawocommented, Jan 19, 2021

ReactiveIndexOperationshas methods for creating indices, writing mappings and settings. What is missing in these methods that you implement your own createIndex()? Is this in a custom ReactiveIndexOperations 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Index API | Elasticsearch Guide [8.5] | Elastic
Adds a JSON document to the specified data stream or index and makes it searchable. If the target is an index and the...
Read more >
Guide How To Add Documents To An Index In Elasticsearch
Complete tutorial on how to add documents to an index in the Elasticsearch service.
Read more >
How to create Index Document in Elastic Search - YouTube
In this video tutorial, we will learn about how to create index documents in Elastic Search.You can visit Elastic Search related videos ...
Read more >
Create index in elasticsearch with different document types
So my index has to store all these segments (JSON documents). I want to search by different combinations of fields and segments like:...
Read more >
How to Create Elasticsearch Indices - Linux Hint
Elasticsearch is one part of the popular ELK stack used for log analytics and search. Applications and systems are constantly logging data that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found