IndexRequest indexRequest = new IndexRequest("my_index");
indexRequest.create(true);
indexRequest.source("{\n" +
" \"settings\" : {\n" +
" \"number_of_shards\" : 1,\n" +
" \"number_of_replicas\" : 0\n" +
" },\n" +
" \"mappings\" : {\n" +
" \"properties\" : {\n" +
" \"message\" : { \"type\" : \"text\" }\n" +
" }\n" +
" },\n" +
" \"aliases\" : {\n" +
" \"twitter_alias\" : {}\n" +
" }\n" +
"}", XContentType.JSON);
IndexResponse indexResponse = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
this code snippet returns
ElasticsearchStatusException[Elasticsearch exception [type=invalid_type_name_exception, reason=mapping type name [_create] can't start with '_' unless it is called [_doc]]
]
error.
The ES 7.8 I am using still creates the index for me but it lacks the mapping part. I wonder if there is a way to fix this problem. Or is it better to use the following code instead?
CreateIndexRequest createIndexRequest = new CreateIndexRequest("twitter");
createIndexRequest.source("{\n" +
" \"settings\" : {\n" +
" \"number_of_shards\" : 1,\n" +
" \"number_of_replicas\" : 0\n" +
" },\n" +
" \"mappings\" : {\n" +
" \"properties\" : {\n" +
" \"message\" : { \"type\" : \"text\" }\n" +
" }\n" +
" },\n" +
" \"aliases\" : {\n" +
" \"twitter_alias\" : {}\n" +
" }\n" +
"}", XContentType.JSON);
CreateIndexResponse createIndexResponse = restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);