在Elasticsearch中搜索字符串数组中的确切字段,并通过最新发布日期进行排序 [英] Search for exact field in an array of strings in elasticsearch with sorting via latest publication date

查看:55
本文介绍了在Elasticsearch中搜索字符串数组中的确切字段,并通过最新发布日期进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是在字符串数组中进行精确的字符串搜索.

如果文档具有发布日期,则还有另一件事.

There is another thing if the document has a publishing date.

{
   "datePublished":"2020-05-22T15:06:00.000Z",
   "locations":[
      "Landkreis Cloppenburg",
      "Berlin"
   ]
}

并使用最新发布日期对它们进行排序.然后如果我在查询中输入了 Landkreis Cloppenburg ,结果将返回:

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"
      }
   }
]

推荐答案

正确的查询应如下所示

{
    "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"
            }
        }
    }
}

这篇关于在Elasticsearch中搜索字符串数组中的确切字段,并通过最新发布日期进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆