Tarun Arora
Tarun Arora

Reputation: 123

How to search data in elastic search from JAVA

I am using elastic search in my project, for searching we have genreally 2 methods:-

What is the difference between the two methods? And, which one is more efficient?

Thanks in advance

Upvotes: 0

Views: 404

Answers (1)

Richa
Richa

Reputation: 7649

Prepare Search :

  • It allows you to search the documents that match the query you specify in setQuery() method. You can also pass filter as per your requirement.
  • It can be executed across one or more indices and across one or more types.
  • When executing a search, it will be broadcasted to all the index/indices shards (round robin between replicas).

PrepareGet:

  • It is like findByid(). You have to specify the id of the document to be fetched.

  • Executed for one type under one index.

  • The Get operation gets hashed into a specific shard id. It then gets redirected to one of the replicas within that shard id and returns the result.

    PrepareGet is more efficient as it fetches the data on the basis of id.

Upvotes: 1

Related Questions