2
votes

I am using Jest to query Elasticsearch and so far it has been great. Jest's documentation says:

Result can be cast to List of domain object;

... and shows this example:

SearchResult result = client.execute(search);
List<SearchResult.Hit<Article, Void>> hits = searchResult.getHits(Article.class);
// or
List<Article> articles = result.getSourceAsObjectList(Article.class);

getSourceAsObjectList is deprecated, and I am using:

List<SearchResult.Hit<ImmutableConceptDocument, Void>> concepts = result.getHits(ImmutableConceptDocument.class);

... Where ImmutableConceptDocument is an immutables generated class - otherwise pretty straight forward POJO, with attributes named as I see under the source of my search results.

However, when I use the above line, I don't get the source properties mapped, I do get other details like score, type, index etc. mapped.

What am I missing? Does the domain class need to have specific Jest annotations or something like that?

I can't see any good examples in the unit tests too. This one maps to Object.class and that does not show me a mapping example.

Here is the immutable class:

@Value.Immutable
public abstract class EsConceptDocument {
    public abstract String term();
    public abstract Category type();
    public abstract List<String> synonyms();
}

... where Category is an enum type.

1
The domain class doesn't need any specific annotations (except if you're willing to deserialize Date objects). Can you show your ImmutableConceptDocument class?Val
Thanks. Added the class.arnab
That's not ImmutableConceptDocument but probably its abstract super class ?Val
Ah, your comment highlighted the problem. Immutable makes the constructor private. I removed immutable annotation and wrote a POJO with a constructor and getters and got it working.arnab
@arnab Hey, I have a similar question here : stackoverflow.com/questions/44557382/… Could you please help ? Thanks!Hormigas

1 Answers

1
votes

As Val pointed out in the comments, this was because immutables.io makes the generated class' constructor private (and exposes a builder).

I removed immutable from this class and wrote a constructor and getters and it worked.