random_score无法正常使用“should”

时间:2014-02-06 17:54:38

标签: 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
}

1 个答案:

答案 0 :(得分:3)

这是因为随机分数乘以原始查询中的_score。如果您希望结果完全基于随机分数,请将boost_mode设置为replace(而不是默认multiply)。

请参阅function_score documentation