elasticsearch - 您可以在Elasticsearch过滤器中引用其他查询吗?

标签 elasticsearch

过滤器查询可以在过滤器索引中引用其他存储的查询文档吗?例如,假设我有以下 bool(boolean) 查询,其_id=1已在渗滤器中建立索引:

{
  "query": {
    "bool": {
      "must": [
        { "term": { "tag": "wow" } }
      ]
    }
  }
}

我可以用_id=2索引另一个查询吗(请注意,我正在组成_percolator_ref_id术语查询关键字):
{
  "query": {
    "bool": {
      "should": [
        { "term": { "tag": "elasticsearch" } },
        { "terms" : { "_percolator_ref_id": [1] } }
      ]
    }
  }
}

如果我渗入以下文件:
{ "tag": "wow" }

我希望_id=1_id=2查询都可以匹配。是否存在诸如_percolator_ref_id之类的功能?

谢谢!

编辑:为了澄清起见,我不预先知道在给定查询中会出现多少个查询引用(例如_id=2查询可能会引用其他10个查询)。

最佳答案

您可以执行以下操作

以下索引中注册了2个查询

PUT myindex
{
    "mappings": {
        "properties": {
            "query1": {
                "type": "percolator"    
            },
            "query": {
                "type": "percolator"
            },
            "field": {
                "type": "text"
            }
        }
    }
}

您可以使用 bool(boolean) 值,必须/应该组合不同的查询
GET /myindex/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "percolate": {
            "field": "query",
            "document": {
              "field": "fox jumps over the lazy dog"
            }
          }
        },
        {
          "percolate": {
            "field": "query1",
            "document": {
              "field": "fox jumps over the lazy dog"
            }
          }
        }
      ]
    }
  }
}

关于elasticsearch - 您可以在Elasticsearch过滤器中引用其他查询吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58122968/

相关文章:

elasticsearch - 如何获取文档的每个分片中的段数 Elasticsearch

c# - C#NEST ElasticSearch搜索并突出显示所有类型的所有字段

json - 如何在Elasticsearch中为格式为JSON的文件创建带有整数字段的索引?

elasticsearch - 计算Elasticsearch聚合的结果

json - window : curl with json data on the command line

plugins - elasticsearch插件更新

javascript - 在ElasticSearch上的嵌套查询

elasticsearch - 使用 Elasticsearch 聚合结果作为过滤器

amazon-web-services - 开始流式传输到Amazon Elasticsearch Service时如何选择不同的Lambda函数

performance - 如何在 ElasticSearch 中为短语查询启用模糊性