1

I'm trying to retrieve some documents from Elasticsearch with the new Java client api, but I can't figure out how to extract nested fields so that the structure would be flattened and easy to search after extraction.

Right now, the response is parametrized and looks like this:

SearchResponse<Model> model = client.search(request, Model.class);

Model:

public class Model  {

private String id;

private NestedClass nestedClass;

public static class NestedClass {
    private String field1;
    private String field2;
}

}

I'm using this client:

        <groupId>co.elastic.clients</groupId>
        <artifactId>elasticsearch-java</artifactId>
        <version>7.17.0</version>

I am able to populate all the fields, but I want the response to be something like this instead:

{ 
    id,
    nestedClass.field1,
    nestedClass.field2,
    ...
}

I am thinking of converting the response to Json after retrieving it, but I guess this will affect performance. Do you know if this can be done directly when searching in ES, without other changes? Thanks

Or Assayag
  • 5,662
  • 13
  • 57
  • 93
B. Bal
  • 121
  • 1
  • 2
  • 11

0 Answers0