elasticsearch - 在弹性搜索中使用 GET API 进行搜索查询
问题描述
我使用的是 7.4 版。我想主要实现三件事。我想根据日期范围进行过滤,然后在“标题”字段中搜索关键字并输出所选字段。以下是我尝试但无法正常工作的代码,请帮助。
POST test/_search
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "Market",
"fields": [
"title",
"message"
]
}
},
"filter": {
"range": {
"published": {
"gte": "now-300d/d",
"lt": "now/d"
}
}
}
}
},
"_source": [
"title",
"message",
"published"
]
}
我得到如下
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 3,
"col": 17
}
],
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 3,
"col": 17
},
"status": 400
}
上面有没有其他方法或任何更正?
解决方案
ES 7.4不支持过滤,我们将使用必须查询
POST <index_name>/_search
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "Market",
"fields": [
"title",
"message"
]
}
},
{
"range": {
"published": {
"gte": "now-300d/d",
"lt": "now/d"
}
}
}
]
}
},
"_source": [
"title",
"message",
"published"
]
}
推荐阅读
- node.js - Socket.emit() 不发送数据
- algorithm - 为什么 Josef Stein 的二进制 GCD 算法的这种实现只适用于某些情况?
- haskell - 数据种类联盟
- sql - 如何在数字(货币)之间添加空格 - Oracle 格式
- sql - 在 from/join 子句中使用和/或选择查询
- vuetify.js - 如何将具有新样式css的类添加到v-dialog,vuetify?
- python - 试图通过蓝牙从arduino传感器发送串行数据到python
- r - rnorm 正在生成非随机的实现
- python - Python 诗歌的依赖版本语法
- swift - Swift - 如何修改文件元数据,如 kMDItemDisplayName?