【发布时间】:2016-05-07 22:01:16
【问题描述】:
我有这个搜索查询在根标题和描述中找到查询搜索词“红狗”,并匹配嵌套的 cmets 文档。
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"
}
}
}
}
]
}
}
}
不幸的是,当我将 cmets 持久保存到 ElasticSearch 时,它们有时为空,是否可以执行某种“如果文档存在则包含”条件?
更新
我仍然遇到同样的错误
[nested] failed to find nested object under path [Comments]
当我尝试使用存在查询时
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"
}
}
}
}
}
}
]
}
}
}
我所有的映射
{
"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"
}
}
}
}
}
}
}
}
还有我的设置
{
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
}
}
【问题讨论】:
-
exists 过滤器应该做你想做的事。 elasticsearch.org/guide/en/elasticsearch/reference/current/…
-
马克,你能发布你的完整地图吗?
-
完成,请看原帖底部。还包括我的原始设置
-
您的映射定义可能存在问题。我创建了以下要点,它运行查询没有任何错误(在 ES 1.4.4 上)gist.github.com/jayhilden/899112a5d0fe09c5f1e9
-
我刚刚检查过它确实适用于“en”索引。它不适用于所有索引(“_all”)。你知道这是为什么吗?是否需要跨所有索引设置默认映射?
标签: elasticsearch