elasticsearch - 如何使用模糊性和通配符查询来查询 elasticsearch 嵌套对象
问题描述
{
"took":1,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"skipped":0,
"failed":0
},
"hits":{
"total":1,
"max_score":1,
"hits":[
{
"_index":"event_11",
"_type":"_doc",
"_id":"1",
"_score":1,
"_source":{
"title":"Event One",
"comments":{
"author":"Alvin",
"author_id":1
}
},
"inner_hits":{
"comments":{
"hits":{
"total":1,
"max_score":1,
"hits":[
{
"_index":"event_11",
"_type":"_doc",
"_id":"1",
"_nested":{
"field":"comments",
"offset":0
},
"_score":1,
"_source":{
"author":"Alvin",
"author_id":1
}
}
]
}
}
}
}
]
}
}
我正在尝试使用以下通配符查询来查询上述数据:
GET event_11/_search
{
"query": {
"nested": {
"path": "comments",
"query": {
"wildcard": {
"comments.author": "Al*"
}
}
}
}
}
上面的查询给出了空的结果集。有人可以帮助我使用通配符和模糊性修复搜索查询吗?我正在使用 ElasticSearch 6 和 Kibana 来创建我的查询。PHP SDK 用于编写来自 PHP 应用程序的查询。
解决方案
You can try this.
{
"query": {
"nested": {
"path": "comments",
"query": {
"bool": {
"should": [
{
"wildcard": {
"comments.author": "real*"
}
},
{
"match": {
"comments.author": {
"query": "reaa",
"fuzziness": "AUTO"
}
}
}
]
}
}
}
}
}
推荐阅读
- testing - 使用 Testcafe 将网络日志与 const 进行比较
- matplotlib - Matplotlib | 如何绘制直线(矩形)
- google-cloud-platform - Configuring smartdocs
- algorithm - 将一个数组拆分为多个子数组以最小化每个单独子数组的总和
- angular - Mat单选按钮波纹效果动画淡出
- javascript - 警告:React.createElement:类型无效——expo reactnative app
- firebase - 如果我向请求添加回调,则无法部署功能
- python - QGraphicsSVGItem 忽略(一些)剪切路径。为什么?
- node.js - Google Drive UI 集成问题:我的应用文件缺少“打开方式...”建议
- javascript - jQuery 函数 history.replaceState() 从 URL 中删除附加参数