0

We are slowly moving our project away from the RestHighLevelClient onto Spring's Api Client. In doing so it looks as though some of the metadata is not coming back as expected.

Here's our simplified POJO:

public class TestDocument {

   @Field(name="_index")
   private String index;

   ...
}

Previously, when using the RestHighLevelClient the field was populated without any issues, however now the value is coming back as null.

My search query is very simple as well. Here's how we're doing it:

SearchHits<TestDocument> hits = esClient.search(query, TestDocument.class, IndexCoordinates.of(index);

Any thoughts on how to populate that property?

Dan
  • 979
  • 1
  • 8
  • 29

1 Answers1

0

There is no Api Client from Spring. Spring Data Elasticsearch now uses the (new) Elasticsearch Java CLient.

What do you expect in _index? The name of the index where the document was retrieved from? That was never mapped by Spring Data Elasticsearch onto a property, but it is returned in each SearchHit<T>

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
  • Yes, I mean the Java client. To answer your question, we expect the name of the index to be returned. Right now we use aliases when searching, but the display is looking for the index name, not the alias. I am not seeing the index name returned in `SearchHit` when I query, only `id`, `score`, `highlightFields`,`sortValues`, and `content`. – Dan May 03 '23 at 15:05
  • I am using `spring-data-elasticsearch-4.0.5-RELEASE` if that makes a difference – Dan May 03 '23 at 15:18
  • The new Elasticsearch client is used from Spring Data Elasticsearch 5.0 on. Spring Data Elasticsearch 4.0 is outdated and has reached end of support in May 2021; all the 4.x versions used the now deprecated `RestHighLevelClient`. That the index name is returned in `SearchHit` was added in 4.1 – P.J.Meisch May 03 '23 at 18:12
  • I upgraded my `spring-data-elastic` version and now I'm able to get the field! Thanks!! – Dan May 03 '23 at 18:36