0

我想按照一些提升规则对我的查询结果进行排序,同时我希望它们尽可能按创建日期排序,如果我添加一个 created_at 排序,它会改变一切,我的结果不再相关。所以我想这样做的唯一方法是提升 created_at 字段(最新的在计算该提升的分数方面具有最大的奖励)但我不知道如何实现它。这是我的查询:

query = {
  "query" : {
    "bool" : {
      "must" : [
        {
          "range" : {
            "deadline" : {
              "gte" : "2016-05-30T11:39:10+02:00"
            }
          }
        },
        {
          "terms" : {
            "state" : [
              "open"
            ]
          }
        },
        {
          "query_string" : {
            "query" : "chant",
            "default_operator" : "AND",
            "analyzer" : "search_francais",
            "fields" : [
              "title^6",
              "description",
              "brand",
              "category_name"
            ]
          }
        }
      ]
    }
  },
  "filter" : {
    "and" : [
      {
        "geo_distance" : {
          "distance" : "40km",
          "location" : {
            "lat" : 48.855736,
            "lon" : 2.32927300000006
          }
        }
      }
    ]
  },
  "sort" : [
    {
      "_score" : "desc"
    },
    #{
    #  "created_at" : "desc"   ==> i tried this but it doesnt change results
    #}
  ]
}
4

1 回答 1

0

尝试在应该阻止中添加您的条件。

i)如果创建的日期应该更接近搜索查询中的值,或者您对日期应该有多接近有任何想法,请给出范围查询。ii) 如果您不确定所有这些值,可以使用衰减函数。在这种情况下,查询应改为功能查询。

 {
  "query" : {
    "bool" : {
      "must" : [
        {
          "range" : {
            "deadline" : {
              "gte" : "2016-05-30T11:39:10+02:00"
            }
          }
        },
        {
          "terms" : {
            "state" : [
              "open"
            ]
          }
        },
        {
          "query_string" : {
            "query" : "chant",
            "default_operator" : "AND",
            "analyzer" : "search_francais",
            "fields" : [
              "title^6",
              "description",
              "brand",
              "category_name"
            ]
          }
        }
      ],
      "should": [
        {"created_at" : "condition here .. "}
      ]
    }
  },
  "filter" : {
    "and" : [
      {
        "geo_distance" : {
          "distance" : "40km",
          "location" : {
            "lat" : 48.855736,
            "lon" : 2.32927300000006
          }
        }
      }
    ]
  }
}
于 2016-05-30T14:25:26.623 回答