use*_*178 9 lucene dsl search elasticsearch
我有以下映射
{
"cloth": {
"dynamic" : false,
"_source" : {"enabled" : false },
"properties": {
"name": {
"type": "string",
"index": "analyzed"
},
"variation": {
"type": "nested",
"properties": {
"size": {
"type": "string",
"index": "not_analyzed"
},
"color": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我无法找到使用字段查询检索嵌套对象字段的方法.
{
"fields" : ["name" , "variation.size", "variation.color"],
"query" : {
"nested" : {
"path" : "variation",
"query" : {
"bool" : {
"must" : [
{ "term" : { "variation.size" : "XXL" } },
{ "term" : { "variation.color" : "red" } }
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
上面的查询返回
"_id" : "1",
"_score" : 1.987628,
"fields" : {
"variation.size" : [ "XXL", "XL" ],
"variation.color" : [ "red", "black" ],
"name" : [ "Test shirt" ]
}
Run Code Online (Sandbox Code Playgroud)
当我尝试
"fields" : ["name" , "variation"]
Run Code Online (Sandbox Code Playgroud)
我收到了错误
状态:400
原因:"ElasticsearchIllegalArgumentException [field [variation]不是叶子字段]"
这是预期的.
如何获取变体对象?
预期结果.我需要整体检索变量对象,以便我可以保留大小和颜色的关联.就像"红色"和"XXL"一样.
"variation" : { "XXL" , "red"}
Run Code Online (Sandbox Code Playgroud)
更新:此索引类型的源已禁用.
如果您使用源过滤,它将返回整个嵌套对象,您的查询将是:
{
"_source": [
"name",
"variation"
],
"query": {
"nested": {
"path": "variation",
"query": {
"bool": {
"must": [
{
"term": {
"variation.size": "XXL"
}
},
{
"term": {
"variation.color": "red"
}
}
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3045 次 |
| 最近记录: |