这是在字符串数组中精确搜索字符串的后续问题。
如果文档具有发布日期,则还有另一件事。
{ "datePublished":"2020-05-22T15:06:00.000Z", "locations":[ "Landkreis Cloppenburg", "Berlin" ] }
并按最新发布日期对它们进行排序。然后,如果我在查询中输入以下内容,则结果将与 Landkreis Cloppenburg 一起返回:
"sort": [ { "doc.datePublished":{ "order":"desc" } } ]
正确的查询应如下所示
{ "sort": [ { "datePublished": { "order": "desc" } } ], "query": { "term": { "location": { "value": "Cloppenburg" } } } }
就像我之前写的答案一样,我只是增强并包含了您的日期字段,所以我的映射看起来像
{ "mappings": { "properties": { "location": { "type": "keyword" }, "datePublished" : { "type" : "date" } } } }