弹性搜索排序

时间:2019-02-27 11:23:44

标签: amazon-web-services sorting elasticsearch

我有一张桌子

[
{
  "id": 123,
  "name": "Ram",
  "status": 1,
  "activity": "Poster Design"
},
{
  "id": 123,
  "name": "Ram",
  "status": 1,
  "activity": "Poster Design"
},
{
  "id": 124,
  "name": "Leo",
  "categories": [
    "A",
    "B",
    "C"
  ],
  "status": 1,
  "activity": "Brochure"
},
{
  "id": 134,
  "name": "Levin",
  "categories": [
    "A",
    "B",
    "C"
  ],
  "status": 1,
  "activity": "3D Printing"
}

]

我想通过对字段活动进行排序来从弹性搜索5.5中获取此数据,但是我需要首先与name =“ Ram”相对应的所有数据,然后保留在单个查询中。

2 个答案:

答案 0 :(得分:0)

您可以使用function score查询根据过滤器(本例中名称为ram)的匹配来增强结果。

以下查询应为您工作

    public static void funcA(object obj)
    {
    }

    public static void funcB(int num)
    {
    }

    public static void performSelectorAfterDelay<T>(Action<T> method, T parameter, double delay)
    {
        Thread thread = new Thread(delegate()
        {
            Thread.Sleep(TimeSpan.FromSeconds(delay));
            uc.BeginInvoke((Action)(() => method(parameter)));
        });
        thread.Start();
    }

    public static void SomeCall()
    {
        performSelectorAfterDelay(new Action<object>(funcA), null, kSecondsWaitAfterTransferToFollowersPage);
        performSelectorAfterDelay(new Action<int>(funcB), 5, kSecondsWaitAfterTransferToFollowersPage);
    }

答案 1 :(得分:0)

我建议结合使用布尔查询和should子句。 您还需要在您的字段上使用sort子句。

相关问题