0

I have written an api to create index by specifying custom settings and mappings using Java High Level Rest Client. Version of Elastic Search is 7.The index is created successfully. The info of api is specified below.

public IndexResponse createIndexWithCustomSettingAndMappings(String indexName, String settings, String fieldsMapping)

After this I tested with localhost:9200/indexName

{"testing":{"aliases":{},"mappings":{"properties":{"category_title_en":{"type":"text"}}},"settings":{"index":{"routing":{"allocation":{"include":{"_tier_preference":"data_content"}}},"number_of_shards":"1","provided_name":"testing"}}}}

After this I have also written an api to add document to an index but I have not specified any mapping because I want to use dynamic mapping and want elastic search to figure out the types itself.

public CreateAndUpdateResponse createDocumentById(@RequestParam String indexName)

This is the controller method. The document is basically a Java Class wherein I feed the values to it and in the service layer I pass it as a String argument by converting the Java POJO to String. The service method info is given below.

public CreateAndUpdateResponse createDocumentById(String indexName, String jsonData).

Here jsonData is the String which is prepared by converting the POJO as mentioned above.

On running this api, the document is inserted into the given index but I don't see any mappings for the fields which have been inserted. Elastic search should have made the use of dynamic mapping.

{"demo":{"aliases":{},"mappings":{"properties":{"{\"index_name\":\"demo\",\"status\":\"success\",\"updated_at\":\"Wed Sep 29 14:12:54 IST 2021\",\"created_at\":\"Wed Sep 29 14:12:54 IST 2021\",\"created_at_epoch\":0}":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}},"settings":{"index":{"routing":{"allocation":{"include":{"_tier_preference":"data_content"}}},"number_of_shards":"1","provided_name":"demo","creation_date":"1632904975248","number_of_replicas":"1","uuid":"1vdUxgafQDeub6GHp2C-IA","version":{"created":"7140099"}}}}}

In this response, you can see the document is inserted in index demo but I don't see the types of all the variables. There is also a field named with type given below in this response but this values looks generic. If elastic search is using dynamic mapping then where we can see what datatype it has given to the fields of the document.

{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}
Aditya
  • 950
  • 8
  • 37
  • Provide the submitted document along with the expected filed types, please. – lkatiforis Sep 30 '21 at 17:02
  • I have mentioned the fields and the output in the description of the question. To make it more clear the fields present in the Java class are indexName, status, createdAt, updatedAt. – Aditya Sep 30 '21 at 18:45
  • the `_mapping` endpoint will show you this, I would check that directly. however I can't see that you have indexed a `createdAt` field in the json examples you have provided, so it's no surprise that it's not mapped anywhere – warkolm Sep 30 '21 at 23:50
  • I have tried the _mapping endpoint but still it does not show data types of fields. The reason I have not provided the mappings because I want to make use of dynamic mapping wherein elastic search should be able to figure out the data types itself. – Aditya Oct 01 '21 at 04:31

0 Answers0