问题
This is a follow-up question of exact string search in an array of strings.
There is another thing if the document has a publishing date.
{
"datePublished":"2020-05-22T15:06:00.000Z",
"locations":[
"Landkreis Cloppenburg",
"Berlin"
]
}
and sort them with the latest publication date. Then the result is coming back with the Landkreis Cloppenburg if I have this in the query:
"sort": [
{
"doc.datePublished":{
"order":"desc"
}
}
]
回答1:
the correct query should be like below
{
"sort": [
{
"datePublished": {
"order": "desc"
}
}
],
"query": {
"term": {
"location": {
"value": "Cloppenburg"
}
}
}
}
As the previous answer was written by me, I just enhanced and included your date field, so my mapping looks like
{
"mappings": {
"properties": {
"location": {
"type": "keyword"
},
"datePublished" : {
"type" : "date"
}
}
}
}
来源:https://stackoverflow.com/questions/62263201/search-for-exact-field-in-an-array-of-strings-in-elasticsearch-with-sorting-via