简体   繁体   English

如何从JAVA弹性搜索中搜索数据

[英]How to search data in elastic search from JAVA

I am using elastic search in my project, for searching we have genreally 2 methods:- 我在我的项目中使用弹性搜索,对于搜索,我们通常有2种方法:-

  • prepareGet prepareGet
  • prepareSearch prepareSearch

What is the difference between the two methods? 两种方法有什么区别? And, which one is more efficient? 而且,哪个更有效?

Thanks in advance 提前致谢

Prepare Search : 准备搜索

  • It allows you to search the documents that match the query you specify in setQuery() method. 它允许您搜索与您在setQuery()方法中指定的查询匹配的文档。 You can also pass filter as per your requirement. 您也可以根据需要通过filter
  • 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 : PrepareGet

  • It is like findByid() . 就像findByid() You have to specify the id of the document to be fetched. 您必须指定要提取的文档的ID。
  • Executed for one type under one index. 在一个索引下对一种类型执行。
  • The Get operation gets hashed into a specific shard id. Get操作将散列到特定的分片ID中。 It then gets redirected to one of the replicas within that shard id and returns the result. 然后将其重定向到该分片ID内的副本之一,并返回结果。

    PrepareGet is more efficient as it fetches the data on the basis of id. PrepareGet效率更高,因为它基于id来获取数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM