Ignore field on mapping and indexing using ElasticSearch and java API

(Achraf Lahlou) #1

I'm developing an application using ElasticSearch, I want to index a document but ignoring some field.

@Document(indexName = "my_index", type = "user")
public class User{

    private Long userId;
    private String name;
    private Adress adresse; //ignored field 

    getters and setters


Thanks in advance

(David Pilato) #2

We don't use annotations as you mentioned in elasticsearch.

Have a look at the java documentation: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/generate.html

(Achraf Lahlou) #3

it's not possible using annotation?
Why can not use annotation?

(David Pilato) #4

Elasticsearch java client does not serialize your java beans to JSON when you index.
Same when you read your data back from elasticsearch.

Use Jackson for this: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/generate.html#beans
With Jackson you can use annotations if you want.

Typically what I'm doing here: https://github.com/dadoonet/legacy-search/blob/01-direct/src/main/java/fr/pilato/demo/legacysearch/domain/Person.java and here https://github.com/dadoonet/legacy-search/blob/01-direct/src/main/java/fr/pilato/demo/legacysearch/dao/ElasticsearchDao.java#L51-L54

(Achraf Lahlou) #5

Hi @dadoonet and thanks for being intersted for my issue.
Im newbie on ElasticSearch and the application im developping uses JPA and SpringData, What about using the Spring Data ElasticSearch with ElasticSearch Repositories.

(David Pilato) #6

I see. I never used it. I can't help more here.

May be some of the authors of the spring-data integration are here?

(system) #7