2
我在基於所選嵌套文檔中的值排序文檔時遇到問題。我使用這樣設置:按嵌套文檔之一的值排序文檔
curl -XPUT 'http://127.0.0.1:9200/test/' -d '
index :
number_of_shards : 1
number_of_replicas : 1
'
curl -XPUT '127.0.0.1:9200/test/item/_mapping' -d '
{
"item" : {
"properties" : {
"name" : {"type" : "string", "store": "yes"},
"children" : {
"properties" : {
"name" : {"type" : "string", "store": "yes"},
"id" : {"type" : "integer", "store": "yes"},
"size" : {"type" : "integer", "store": "yes"}
},
"type": "nested"
}
}
}
}'
curl -XPUT 'http://localhost:9200/test/item/1' -d '{
"name" : "item1",
"children": [
{
"id": 11,
"size": 15
},
{
"id":3,
"size": 6
}
]
}
}'
curl -XPUT 'http://localhost:9200/test/item/2' -d '{
"name" : "item2",
"children": [
{
"id": 1,
"size": 2
},
{
"id":3,
"size": 6
}
]
}
}'
curl -XPUT 'http://localhost:9200/test/item/3' -d '{
"name" : "item3",
"children": [
{
"id": 1,
"size": 7
},
{
"id":3,
"size": 36
}
]
}
}'
curl -XPUT 'http://localhost:9200/test/item/4' -d '{
"name" : "item4",
"children": [
{
"id": 1,
"size": 11
},
{
"id":3,
"size": 16
}
]
}
}'
我試圖檢索與選定的子ID文件,就由孩子選擇大小進行排序。所以查詢的樣子:
curl -XGET 'http://127.0.0.1:9200/test/item/_search?pretty=1' -d '
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"filter": {
"term": {
"id": 1
}
},
"path": "children"
}
}
}
},
"sort": [
{
"children.size": {
"order": "asc",
"nested_filter": {
"nested": {
"filter": {
"term": {
"id": 1
}
},
"path": "children"
}
}
}
}
]
}
'
在此查詢不管我投入「順序」域(ASC或DESC),返回的文件都在相同的順序。什麼可能是問題?
謝謝。這很奇怪,ES沒有提出mu查詢的問題。另外,我已經使用ES庫準備了這種排序過濾器,我希望他們能夠準備適當的消息。 – szymond 2015-02-14 09:39:53