Elasticsearch 通过另一个文档查找文档

标签 elasticsearch

我想在 elasticsearch 中搜索与 id docId 的给定文档具有完全相同字段的文档。例如用户使用 docId 调用 api,我想过滤文档,以便返回的所有文档都满足 docId 中的某些参数。

例如,我可以这样查询 Elasticsearch 吗:

POST similarTerms/_search
{
    "fields": [
       "_id", "title"
    ]   ,
    "filter": {
    "query": {"match": {
       "title": doc[docId].title
    }}
    }, 
    "size": 30

}

我知道我可以使用 docId 获取文档,然后我可以准备上述查询,但我能否以某种方式避免网络跳转,因为即使是毫秒级的时间改进对我的应用程序来说也是非常重要的。

谢谢

最佳答案

这是“更像这样”api 的教科书场景。引自 the docs :

The more like this (mlt) API allows to get documents that are "like" a specified document. Here is an example:

$ curl -XGET 'http://localhost:9200/twitter/tweet/1/_mlt?mlt_fields=tag,content&min_doc_freq=1'

The API simply results in executing a search request with moreLikeThis query (http parameters match the parameters to the more_like_this query). This means that the body of the request can optionally include all the request body options in the search API (aggs, from/to and so on). Internally, the more like this API is equivalent to performing a boolean query of more_like_this_field queries, with one query per specified mlt_fields.

如果您计划(像我一样)仅使用一个文档进行测试,请确保您还设置了 min_term_freq=0min_doc_freq=0: GET/my_index/locations/1/_mlt?min_term_freq=0&min_doc_freq=0

关于Elasticsearch 通过另一个文档查找文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26977932/

相关文章:

elasticsearch - 仅针对 elasticsearch 上的特定索引禁用动态映射创建?

node.js - NodeJS- Elasticsearch 以插入要索引的数据

search - Elasticsearch术语统计查询未正确分组

regex - Kibana 查询精确匹配

elasticsearch - 在 Windows 中运行 Filebeat

docker - 无法连接到 docker 中端口9300上的Elasticsearch

search - Elasticsearch 中的索引和搜索分析器:将准确的字符串作为第一个结果时遇到麻烦

spring-boot - 使用 Spring Boot 连接到 Elasticsearch 6.2.3

ElasticSearch - 每个节点的最佳分片数量

elasticsearch - Elasticsearch-按嵌套的多字段排序