Zo the Relativist
Zo the Relativist

Reputation: 117

Syntax for msearch in new Elastic Java Api

I am migrating my existing code from the old Elasticsearch Java API to the Java API (so, replacing RestHighLevelClient with ElasticsearchClient).

The new API (I'm writing in Scala) basically works like:

val resp = client.msearch(searchRequest, Product.class)
val products: List[Product] = resp.hits().hits()

But the whole point of msearch is to submit many queries to the ES server in a single HTTP request, right? And those queries don't necessarily have the same return schema.

What is the correct way to write this so that you have some base class Product, and then some subclass Product1 that is the return type of query #1, and some other subclass Product2 that is the return type of query #2? Does the new API not support this? The docs do not give clear guidance, and neither do the javadoc.

Upvotes: 0

Views: 743

Answers (1)

Abhishek Singh
Abhishek Singh

Reputation: 246

You can use Object.class while fetching data from different indexes as below.

val resp = client.msearch(searchRequest, Object.class)

Upvotes: 1

Related Questions