有人能帮我理解嵌套的弹性意味着什么吗。在文档中,examples是一个示例,它没有显示文档对象的样子。看起来我应该想象一下来自搜索查询的映射。查询如下:
POST /_search
{
"query": {
"nested": {
"path": "parent",
"query": {
"bool": {
"must": {"range": {"parent.age": {"gte": 21}}},
"filter": {
"nested": {
"path": "parent.child",
"query": {"match": {"parent.child.name": "matt"}}
}
}
}
}
}
},
"sort" : [
{
"parent.child.age" : {
"mode" : "min",
"order" : "asc",
"nested": {
"path": "parent",
"filter": {
"range": {"parent.age": {"gte": 21}}
},
"nested": {
"path": "parent.child",
"filter": {
"match": {"parent.child.name": "matt"}
}
}
}
}
}
]
}
有人能写一个文档结构来处理这个查询吗?
发布于 2018-09-27 05:53:01
就像这样。
{
"parent": {
"name": "Elasti Sorch",
"age": 23,
"child": [
{
"name": "Kibana Lion",
"age": 12
},
{
"name": "Matt",
"age": 15
}
]
}
}
发布于 2018-10-01 03:00:28
在弹性嵌套的意思是它是一个对象数组。要在弹性搜索中将对象数组存储到字段中,您必须在创建索引时将字段映射到嵌套字段。
PUT parent
{
"mappings": {
"doc":{
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "integer"
},
"child":{
"type": "nested",
"properties": {
"name":{
"type":"text"
},
"age":{
"type":"integer"
}
}
}
}
}
}
}
并插入一个示例嵌套文档cab,如下所示
POST parent/doc
{
"name":"abc",
"age":50,
"child":[
{
"name":"son1",
"age":25
},
{
"name":"adughter1",
"age":20
}
]
}
https://stackoverflow.com/questions/52538076
复制