【问题标题】:Elasticsearch filter query does not return any documentElasticsearch 过滤器查询不返回任何文档
【发布时间】:2021-06-05 01:07:29
【问题描述】:

我不明白为什么如果我使用这样的过滤器查询 Elasticsearch:

 curl -H'content-type: application/json' "localhost:9200/.kibana/_search" -d '{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "type": "index-pattern"
          }
        }
      ]
    }
  }
}'
{"took":0,"timed_out":false,"_shards":{"total":4,"successful":4,"skipped":0,"failed":0},"hits":{"total":{"value":0,"relation":"eq"},"max_score":null,"hits":[]}}

如您所见,我的结果集为空。 但相反,我确实有一个“类型”字段等于“索引模式”的文档。

  {
    "_index": ".kibana",
    "_type": "_doc",
    "_id": "index-pattern:c37de740-7e94-11eb-b6c2-4302716621be",
    "_score": 0,
    "_source": {
      "index-pattern": {
        "title": "r*",
        "timeFieldName": "@timestamp",
        "fields": "<omitted - too long>"
      },
      "type": "index-pattern",
      "references": [],
      "migrationVersion": {
        "index-pattern": "7.6.0"
      },
      "updated_at": "2021-03-06T15:58:18.062Z"
    }
  }

我的查询有什么问题?

【问题讨论】:

  • 我目前无权访问任何本地 Elasticsearch 实例,但 type 字段的类型是什么? keyword, text?
  • @EvaldasBuinauskas type 始终是 keyword,至少在我所有的 kibana 实例中是这样。 @sscarduzio 可以请仔细检查映射吗?另外,直接访问该 ID,即curl localhost:9200/.kibana/_doc/index-pattern:c37de740-7e94-11eb-b6c2-4302716621be 会产生什么吗?
  • @EvaldasBuinauskas 来自 GET /.kibana,我看到了映射。这是类型字段:“type”:{“type”:“text”,“fields”:{“keyword”:{“type”:“keyword”,“ignore_above”:256}}},
  • @JoeSorocin,是的,该文档全部归结为: curl localhost:9200/.kibana/_doc/index-pattern:c37de740-7e94-11eb-b6c2-4302716621be

标签: elasticsearch elasticsearch-dsl


【解决方案1】:

type 字段默认映射为text 并且您想对其应用term 查询时,连字符将阻止查询匹配,因为textthe standard analyzer 分析在摄取时删除连字符和其他特殊字符。话虽如此,term query 返回的文档包含 exact 匹配(包括特殊字符),这导致您的原始查询不返回任何内容。

所以将.keyword multi-field 改为:

curl -H'content-type: application/json' "localhost:9200/.kibana/_search" -d '{
  "query": {
    "bool": {
      "filter": [
        {
          "term.keyword": {
            "type": "index-pattern"
          }
        }
      ]
    }
  }
}'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 1970-01-01
    相关资源
    最近更新 更多