random_score 不能与“should”一起正常工作

And*_*Vos 2 elasticsearch

在下面的代码中,无论我将种子设置为什么,我总是首先获得“Alexander McQueen”产品。

如何更改搜索查询以正确排列结果?

{
  "query": {
    "function_score": {
      "random_score": {
        "seed": 99287
      },
      "query": {
        "bool": {
          "should": [
            {
              "bool": {
                "must": [
                  {
                    "query_string": {
                      "query": "(adidas originals)",
                      "default_operator": "AND",
                      "fields": [
                        "name^4",
                        "description"
                      ]
                    }
                  },
                  {
                    "terms": {
                      "category": [
                        "Fashion",
                        "Sports",
                        "Other",
                        ""
                      ]
                    }
                  },
                  {
                    "term": {
                      "currency": {
                        "term": "USD"
                      }
                    }
                  }
                ]
              }
            },
            {
              "bool": {
                "must": [
                  {
                    "query_string": {
                      "query": "(alexander mcqueen)",
                      "default_operator": "AND",
                      "fields": [
                        "name^4",
                        "description"
                      ]
                    }
                  },
                  {
                    "terms": {
                      "category": [
                        "Fashion"
                      ]
                    }
                  },
                  {
                    "term": {
                      "currency": {
                        "term": "USD"
                      }
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
  },
  "size": 40,
  "from": 0
}
Run Code Online (Sandbox Code Playgroud)

DrT*_*ech 6

这是因为随机分数乘以_score原始查询的分数。如果您希望结果纯粹基于随机分数,则将 设为boost_modereplace而不是默认值multiply)。

请参阅function_score文档