3

我需要修改这个查询,以便弹性搜索不会它打分。我希望我的自定义过滤器分数是唯一给任何结果打分的东西。我该如何做到这一点?

每条记录都应该只有 0、100 或 1000 分。

{
  "size":50, 
  "from":0, 
  "query" : {
    "custom_filters_score" : {
      "query" : {
        "filtered" : {
          "query" : {
            "bool" : {
              "must" : [
                {"term":{"type":"alpha"}}, 
                {"field":{"sector":"exists"}}, 
                {"field":{"sector.sub":"exists"}}, 
                {"field":{"alpha_sector.sub.categories":"second"}}, 
                {"field":{"beta_sector.sub.columns":"first"}}, 
                {"term":{"beta_type":"beta"}}, 
                {"term":{"area":"624"}}
              ]
            }
          }, 
          "filter" : {
            "or" : [
              {
                "and" : [
                  {"term":{"area":"624"}}, 
                  {"term":{"start":"07242013"}}
                ]
              }, 
              {
                "and" : [
                  {"term":{"area":"624"}}, 
                  {"term":{"start":"blank"}}
                ]
              }
            ]
          }
        }
      }, 
      "filters" : [
        {"filter":{"term":{"resource":5726}}, "boost":"1000"}, 
        {"filter":{"term":{"alpha_resource":5726}}, "boost":"100"}
      ], 
      "score_mode":"sum"
    }
  }
}
4

1 回答 1

3

我不太确定你想在这里实现什么

            {"field":{"sector":"exists"}}, 
            {"field":{"sector.sub":"exists"}},

但总的来说,如果您不希望部分查询影响分数,只需将其设置为过滤器即可。将“bool”与“term”过滤器一起使用会更好,而不是“and”/“or”/“not”

{
  "size":50, 
  "from":0, 
  "query" : {
    "custom_filters_score" : {
      "query" : {
        "filtered" : {
          "query" : {
            "match_all": {}
          }, 
          "filter" : {
            "bool" : {
              "must" : [
                {"term":{"type":"alpha"}}, 
                {"query":{"field":{"sector":"exists"}}}, 
                {"query":{"field":{"sector.sub":"exists"}}}, 
                {"query":{"field":{"alpha_sector.sub.categories":"second"}}}, 
                {"query":{"field":{"beta_sector.sub.columns":"first"}}}, 
                {"term":{"beta_type":"beta"}}, 
                {"term":{"area":"624"}}
              ],
              "should" : [
                {
                  "bool" : {
                    "must" : [
                      {"term":{"area":"624"}}, 
                      {"term":{"start":"07242013"}}
                    ]
                  }
                }, 
                {
                  "bool" : {
                    "must": [
                      {"term":{"area":"624"}}, 
                      {"term":{"start":"blank"}}
                    ]
                  }
                }
              ]
            }
          }
        }
      }, 
      "filters" : [
        {"filter":{"term":{"resource":5726}}, "boost":"1000"}, 
        {"filter":{"term":{"alpha_resource":5726}}, "boost":"100"}
      ], 
      "score_mode":"total"
    }
  }
}
于 2013-07-20T01:30:09.077 回答