elasticsearch - 如何在 Elasticsearch 中的 match_all 中使用过滤器

标签 elasticsearch dsl

查询如下{"from" : 0, "size" : 100,"query": {"match_all": {}}})我需要 filter来自 match_all if nametest我试过 {"from" : 0, "size" : 100,"query": {"match_all": {}}, "filter": [ "term": { "name": "test" }}]}我收到错误“[过滤器]中 START_ARRAY 的未知键。”)

最佳答案

您需要将您的查询包装在一个 bool 查询中,试试这个搜索查询:

    {
  "from":0,
  "size":10,
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": [
        {
          "term": {
           "grocery_name": "elastic"
          }
        }
      ]
    }
  }
}
更新 1:
根据@Nons提到的评论
查询查询:

Terms query return documents that contain an exact term in a provided field.

{
  "from":0,
  "size":10,
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": [
        {
          "term": {
           "parentName.keyword": "Developer"    <-- note this
          }
        }
      ]
    }
  }
}
搜索结果:
"hits": [
      {
        "_index": "stof_64275684",
        "_type": "_doc",
        "_id": "1",
        "_score": 1.0,
        "_source": {
          "id": "1",
          "name": "A",
          "parentName": "Developer",
          "Data": [
            {
              "id": "455",
              "name": "Google",
              "lastUpdatedDate": "2020-09-10",
              "parent_id": "1"
            }
          ],
          "Function": [
            {
              "id": "1",
              "name": "Major"
            }
          ]
        }
      }
    ]

You can even use a match query where the provided text is analyzed before matching.

{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "must": {
        "match": {
          "parentName": "developer"
        }
      }
    }
  }
}

关于elasticsearch - 如何在 Elasticsearch 中的 match_all 中使用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64275684/

相关文章:

perl - Prolog 作为 DSL 来生成 perl 代码?

windows - 无法远程访问 Kibana

elasticsearch - 如果在特定时间没有任何反应,则DateHistogram Facet返回零

elasticsearch - ElasticSearch 6.2 中的 Multi-Tenancy

java - Lucene 搜索最长公共(public)子串

regex - 是否有用于编写正则表达式的 DSL?

groovy - 带有 Groovy 的 DSL -> 传递参数值

elasticsearch - 最大虚拟内存区域 vm.max_map_count [65530] 太低,至少增加到 [262144]

spring - 如何加入多个queryDSL表

f# - 不带 for..in..do 的扩展计算表达式