[英]Elasticsearch nested query and sorting
有人可以幫助我了解Elastic嵌套的含義。 在文檔中https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/search-request-sort.html#_nested_sorting_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"}
}
}
}
}
}
]
}
有人可以寫一個文檔結構來執行此查詢嗎?
這樣的事情。
{
"parent": {
"name": "Elasti Sorch",
"age": 23,
"child": [
{
"name": "Kibana Lion",
"age": 12
},
{
"name": "Matt",
"age": 15
}
]
}
}
在彈性嵌套中意味着它是一個對象數組。 要將對象數組存儲到彈性搜索的字段中,必須在創建索引時將字段映射到嵌套的字段。
PUT parent
{
"mappings": {
"doc":{
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "integer"
},
"child":{
"type": "nested",
"properties": {
"name":{
"type":"text"
},
"age":{
"type":"integer"
}
}
}
}
}
}
}
並像這樣插入一個樣本嵌套文檔駕駛室
POST parent/doc
{
"name":"abc",
"age":50,
"child":[
{
"name":"son1",
"age":25
},
{
"name":"adughter1",
"age":20
}
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.