2

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.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
or9ob
  • 2,313
  • 4
  • 25
  • 45
  • 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 Jan 11 '17 at 05:28
  • Thanks. Added the class. – or9ob Jan 11 '17 at 16:52
  • 1
    That's not `ImmutableConceptDocument` but probably its abstract super class ? – Val Jan 11 '17 at 16:54
  • 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. – or9ob Jan 11 '17 at 18:56
  • @arnab Hey, I have a similar question here : https://stackoverflow.com/questions/44557382/jest-elasticsearch-search-api-hits-mapping Could you please help ? Thanks! – Hormigas Jun 16 '17 at 04:51

1 Answers1

1

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.

or9ob
  • 2,313
  • 4
  • 25
  • 45