ElasticSearch仅查询嵌套,如果它存在 [英] ElasticSearch only query nested if it exists
问题描述
我有这个搜索查询在根标题和描述中找到查询搜索词红狗,并且还匹配嵌套的注释文档。
GET / _all / video / _search
{
query:{
bool:{
should:[
{
multi_match:{
查询:红狗,
fields:[
标题,
说明
],
type:cross_fields,
operator:和
}
},
{
nested
path:评论,
查询:{
multi_match:{
查询:红狗,
:[
Comment.Description,
Comment.Description.folded
],
type:cross_fields,
operator:和
}
}
}
}
]
}
}
}
不幸的是,对我来说,评论是有时候我将它们保留到ElasticSearch时是空的,是否可以做某种包含文件是否存在条件?
更新 p>
我仍然收到相同的错误
[嵌套]找不到嵌套对象在路径下[评论]
当我尝试查询使用存在
GET / _all / video / _search
{
查询:{
bool:{
should:[
{
multi_match:{
query:lisa,
fields:[
标题,
说明
],
type:cross_fields,
运算符:和
}
} ,
{
嵌套:{
路径:注释,
查询:{
过滤:{
查询:{
match_all:{}
},
filter:{
exists:{
field:Comments.Description
}
}
}
}
}
}
]
}
}
}
M所有的y映射
{
en:{
mappings:{
video:{
properties:{
评论:{
type:nested,
properties:{
说明:{
type:string,
analyzer:english,
fields:{
folding:{
type:string,
analyzer:folding
}
}
}
}
},
说明:{
type:string,
analyzer:english,
fields:{
folding:{
type:string,
a nalyzer:折叠
}
}
},
标题:{
type:string,
:$
fields:{
折叠:{
type:string,
analyzer:folding
}
}
}
}
}
}
}
}
我的设置
{
settings :{
analysis:{
analyzer:{
folding:{
tokenizer:standard,
filter
小写,
asciifolding
]
}
}
}
}
}
原来我有一个奇迹索引,没有我的类型的映射。我删除了插件所有索引都很好搜索。
I have this search query to find the query search term "red dog" in the root Title and Description and also match the nested comments document.
GET /_all/video/_search
{
"query":{
"bool":{
"should":[
{
"multi_match":{
"query":"red dog",
"fields":[
"Title",
"Description"
],
"type": "cross_fields",
"operator":"and"
}
},
{
"nested":{
"path":"Comments",
"query":{
"multi_match":{
"query":"red dog",
"fields":[
"Comments.Description",
"Comments.Description.folded"
],
"type": "cross_fields",
"operator":"and"
}
}
}
}
]
}
}
}
Unfortunately for me, comments are sometimes null when I persist them to ElasticSearch, is it possible to do some sort of "include if document exists" condition?
Update
I still get the same error
[nested] failed to find nested object under path [Comments]
When I try to query using exists
GET /_all/video/_search
{
"query":{
"bool":{
"should":[
{
"multi_match":{
"query":"lisa",
"fields":[
"Title",
"Description"
],
"type":"cross_fields",
"operator":"and"
}
},
{
"nested":{
"path":"Comments",
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"exists":{
"field":"Comments.Description"
}
}
}
}
}
}
]
}
}
}
My mapping for everything
{
"en":{
"mappings":{
"video":{
"properties":{
"Comments":{
"type":"nested",
"properties":{
"Description":{
"type":"string",
"analyzer":"english",
"fields":{
"folded":{
"type":"string",
"analyzer":"folding"
}
}
}
}
},
"Description":{
"type":"string",
"analyzer":"english",
"fields":{
"folded":{
"type":"string",
"analyzer":"folding"
}
}
},
"Title":{
"type":"string",
"analyzer":"english",
"fields":{
"folded":{
"type":"string",
"analyzer":"folding"
}
}
}
}
}
}
}
}
And my settings
{
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
}
}
It turns out I had a marvel index which didn't have the mapping for my type in. I deleted the plugin and it was fine searching across all indexes.
这篇关于ElasticSearch仅查询嵌套,如果它存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!