1

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"
      }
   }
]
2
  • can you share youe complete query? Commented Jun 8, 2020 at 13:30
  • GET article/_search { "sort": [ { "doc.datePublished": { "order": "desc" } } ], "query": { "bool": { "must": [ { "match": { "locations": { "query": "Cloppenburg" } } } ] } } } Commented Jun 8, 2020 at 13:31

1 Answer 1

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"
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

you are a rockstar, million thanks :) Please upvote my question :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.