Post过滤器查询中的功能分数。(elasticsearch)

时间:2015-11-11 12:48:03

标签: lucene elasticsearch

我运行了以下这些查询。 此查询为我提供了预期的正确分数。

{
  "query": {
    "filtered": {
      "query": {
        "function_score": {
          "query": {
            "bool": {
              "should": [
                {
                  "match": {
                    "categorytags_snow": "gyms"
                  }
                },
                {
                  "match": {
                    "locationtags_snow": "gyms"
                  }
                },
                {
                  "match": {
                    "offerings_snow": ""
                  }
                },
                {
                  "match": {
                    "title_snow": "gyms"
                  }
                },
                {
                  "match": {
                    "locationcluster_snow": "gyms"
                  }
                },
                {
                  "match": {
                    "facilities_snow": "gyms in bandra"
                  }
                },
                {
                  "match": {
                    "info_service_snow": "gyms"
                  }
                }
              ]
            }
          },
          "functions": [
            {
              "filter": {
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "categorytags_snow": "gyms"
                        }
                      }
                    ]
                  }
                }
              },
              "boost_factor": 8
            },
            {
              "filter": {
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "locationtags_snow": "gyms"
                        }
                      }
                    ]
                  }
                }
              },
              "boost_factor": 10
            },
            {
              "filter": {
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "offerings_snow": "gyms"
                        }
                      }
                    ]
                  }
                }
              },
              "boost_factor": 4
            },
            {
              "filter": {
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "title_snow": "gyms"
                        }
                      }
                    ]
                  }
                }
              },
              "boost_factor": 12
            },
            {
              "filter": {
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "locationcluster_snow": "gyms"
                        }
                      }
                    ]
                  }
                }
              },
              "boost_factor": 2
            },
            {
              "filter": {
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "facilities_snow": "gyms"
                        }
                      }
                    ]
                  }
                }
              },
              "boost_factor": 2
            },
            {
              "filter": {
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "info_service_snow": "gyms"
                        }
                      }
                    ]
                  }
                }
              },
              "boost_factor": 6
            }
          ],
          "boost_mode": "max",
          "score_mode": "sum"
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "term": {
                "city": "bankok"
              }
            }
          ]
        }
      }
    }
  }
}

虽然我使用post_filter来包装我的查询的查询不是计算所需的分数(分数总是1)

{
  "post_filter": {
    "query": {
      "filtered": {
        "query": {
          "function_score": {
            "query": {
              "bool": {
                "should": [
                  {
                    "match": {
                      "categorytags_snow": "gyms"
                    }
                  },
                  {
                    "match": {
                      "locationtags_snow": "gyms"
                    }
                  },
                  {
                    "match": {
                      "offerings_snow": "gyms"
                    }
                  },
                  {
                    "match": {
                      "title_snow": "gyms "
                    }
                  },
                  {
                    "match": {
                      "locationcluster_snow": "gyms"
                    }
                  },
                  {
                    "match": {
                      "facilities_snow": "gyms"
                    }
                  },
                  {
                    "match": {
                      "info_service_snow": "gyms"
                    }
                  }
                ]
              }
            },
            "functions": [
              {
                "filter": {
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "match": {
                            "categorytags_snow": "gyms"
                          }
                        }
                      ]
                    }
                  }
                },
                "boost_factor": 8
              },
              {
                "filter": {
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "match": {
                            "locationtags_snow": "gyms"
                          }
                        }
                      ]
                    }
                  }
                },
                "boost_factor": 10
              },
              {
                "filter": {
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "match": {
                            "offerings_snow": "gyms"
                          }
                        }
                      ]
                    }
                  }
                },
                "boost_factor": 4
              },
              {
                "filter": {
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "match": {
                            "title_snow": "gyms"
                          }
                        }
                      ]
                    }
                  }
                },
                "boost_factor": 12
              },
              {
                "filter": {
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "match": {
                            "locationcluster_snow": "gyms"
                          }
                        }
                      ]
                    }
                  }
                },
                "boost_factor": 2
              },
              {
                "filter": {
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "match": {
                            "facilities_snow": "gyms"
                          }
                        }
                      ]
                    }
                  }
                },
                "boost_factor": 2
              },
              {
                "filter": {
                  "query": {
                    "bool": {
                      "should": [
                        {
                          "match": {
                            "info_service_snow": "gyms"
                          }
                        }
                      ]
                    }
                  }
                },
                "boost_factor": 6
              }
            ],
            "score_mode": "sum"
          }
        },
        "filter": {"bool": {
          "must": [
            {
              "term": {
                "city": "bankok"
              }
            }
          ]
        }}
      }
    }
  }
}

就像post_filter中的查询不支持function_score。

提前致谢

1 个答案:

答案 0 :(得分:1)

正如official docdefinitive guide中所述,预计会出现此问题,post_filter中的任何内容都会在> 后执行,并且不会影响查询范围,因此也不会影响分数。

post_filter基本上是一个过滤器,过滤器不影响评分,总是会返回得分1。