0

In elastic search, I can disable the _source field like :-

  PUT tweets
    {
      "mappings": {
        "tweet": {
          "_source": {
            "enabled": false
          }
        }
      }}

How to achieve this using spring data-elasticsearch ?

1 Answer 1

0

We can put this mapping by:-

1) hard coded 2) can be read from a properties file 3) build it using Xcontentbuilder

We can use the ElasticsearchTemplate class provided by spring data to do this like :-

           if (!elasticsearchTemplate.indexExists(esIndex)) {
                elasticsearchTemplate.createIndex(esIndex);
                elasticsearchTemplate.putMapping(esIndex, esType,mappingObject);
             }

This mappingObject is a string read from properties file. It can be like this :-

es-configs.properties

mapping={"_source": {"includes": [ "id","name","marks","grade"],"excludes": ["contact_info","phone_num"]}}

In this case we are excluding fields contact_info and phone_num. So those fields won't be included in _source of index. This is the case when we use spring data elasticsearch. If you are not using spring data then we can do the same with Xcontentbuilder.

Sign up to request clarification or add additional context in comments.

4 Comments

Can you provide a more detailed example? Thanks.
@AlessandroC : Hi,I've edited the question. Comment here if you need any help! cheers :)
@Sachin, can we add or remove fields from es-configs.properties as per requirement? we intend to use spring data elastic search and in some request we want to return all fields and in other we want to return only few fields, is this possible in spring data?
I think this would help you : stackoverflow.com/questions/38237084/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.