Skip to content

Instantly share code, notes, and snippets.

@EECOLOR
Created November 10, 2015 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EECOLOR/2db9a1ec9d6d5c791ea6 to your computer and use it in GitHub Desktop.
Save EECOLOR/2db9a1ec9d6d5c791ea6 to your computer and use it in GitHub Desktop.
Elasticsearch nested sort problem
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