Created
November 10, 2015 07:40
-
-
Save EECOLOR/2db9a1ec9d6d5c791ea6 to your computer and use it in GitHub Desktop.
Elasticsearch nested sort problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT /testindex | |
{ | |
"settings": { | |
"number_of_replicas": 0, | |
"number_of_shards": 1 | |
}, | |
"mappings": { | |
"testtype": { | |
"dynamic": "strict", | |
"properties": { | |
"organisation": { | |
"type": "object", | |
"properties": { | |
"code": { | |
"type": "string", | |
"index": "not_analyzed" | |
} | |
} | |
}, | |
"publications": { | |
"type": "nested", | |
"properties": { | |
"dateEnd": { | |
"type": "long" | |
}, | |
"dateStart": { | |
"type": "long" | |
}, | |
"code": { | |
"type": "string", | |
"index": "not_analyzed" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
PUT /testindex/testtype/a | |
{ | |
"organisation": { | |
"code": "01310" | |
}, | |
"publications": [ | |
{ | |
"dateEnd": 5, | |
"dateStart": 1, | |
"code": "PUB.02" | |
}, | |
{ | |
"dateEnd": 5, | |
"dateStart": 2, | |
"code": "PUB.06" | |
} | |
] | |
} | |
PUT /testindex/testtype/b | |
{ | |
"organisation": { | |
"code": "01312" | |
}, | |
"publications": [ | |
{ | |
"dateEnd": 5, | |
"dateStart": 1, | |
"code": "PUB.02" | |
}, | |
{ | |
"dateEnd": 5, | |
"dateStart": 2, | |
"code": "PUB.06" | |
} | |
] | |
} | |
GET /testindex/testtype/_search | |
{ | |
"sort": { | |
"publications.dateStart": { | |
"mode": "min", | |
"order": "desc", | |
"nested_filter": { | |
"or": [ | |
{ | |
"and": [ | |
{ | |
"term": { | |
"organisation.code": "01310" | |
} | |
}, | |
{ | |
"term": { | |
"publications.code": "PUB.02" | |
} | |
} | |
] | |
}, | |
{ | |
"term": { | |
"publications.code": "PUB.06" | |
} | |
} | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment