【发布时间】:2015-02-09 05:13:12
【问题描述】:
我在根据所选嵌套文档中的值对文档进行排序时遇到问题。我正在使用这样的设置:
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"
}
}
}
}
]
}
'
在这个查询中,无论我在“order”字段中输入什么(asc 或 desc),返回的文档都是相同的顺序。可能有什么问题?
【问题讨论】:
标签: sorting elasticsearch