elasticsearch - 这些elasticsearch查询有什么区别?

标签 elasticsearch

我有以下 Elasticsearch 查询,返回大量结果。

{
    "query": {
        "multi_match": {
            "query": "swartz",
            "fields": ["notes"]
        }
    },
    "size": 20,
    "from": 0,
    "sort": {
        "last_modified_date": {
            "order": "desc"
        }
    }
} 
我正在尝试将其重做为 bool(boolean) 查询,以便可以添加should和must_not,但是没有任何结果,我不确定为什么。
{
    "query": {
        "bool": {
            "must": [
                {"term": { "notes": "swartz" }}
            ]
        }
    },
    "size": 20,
    "from": 0,
    "sort": {
        "last_modified_date": {
            "order": "desc"
        }
    }
}
我得到的不是结果,而是结果。
  "took" : 6,
  "timed_out" : false,
  "_shards" : {
    "total" : 6,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 1,
    "failures" : [
      {
        "shard" : 0,
        "index" : ".kibana_1",
        "node" : "E2fjoon_Smm5m7LFcQp9XQ",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "No mapping found for [last_modified_date] in order to sort on",
          "index_uuid" : "0pZdhm_nRXWiWGcqFgvvHQ",
          "index" : ".kibana_1"
        }
      }
    ]
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}
首先,我不确定为什么会得到结果,并且它对第一个查询的排序正确,其次,即使我从第二个查询中删除了排序,也仍然没有结果。

最佳答案

首先,您使用匹配查询将在“注释”内容中的某个位置查找任何出现的“swartz”。
在SQL世界中,它类似于:

where notes ilike "%swartz%"
在第二个查询中,您将使用术语查询,该查询将在字段中寻找完美的相等性。
在SQL中:
 where "notes"=="swartz"
它可能可以解释你的行为
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html

关于elasticsearch - 这些elasticsearch查询有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63513092/

相关文章:

elasticsearch - Elasticsearch前缀查询不适用于日期

powershell - 系统在Powershell中找不到路径/命令未找到错误

json - 我想使用powershell将convert.d csv加载到json文件文档以进行elasticsearch

elasticsearch - 使用logstash和 Elasticsearch 进行自定义解析

search - ElasticSearch-查询文档:所有给定标签在嵌套文档中至少出现一次

elasticsearch - 是否可以在 Kibana 中运行 elasticsearch 聚合查询?

elasticsearch - 如何从Logstash中filebeat提供的源值中获取文件名?

dynamic - 为嵌套文档定义动态 not_analyzed 字段

elasticsearch - Elasticsearch 建议返回零结果

elasticsearch - Elasticsearch,为什么添加元素总是为空