ElasticSearch结合了匹配和功能评分查询

时间:2015-08-12 20:32:44

标签: indexing elasticsearch lucene

我有一个复杂的查询在elasticsearch中运行,跨越多个字段(嵌套和非嵌套)。我在bool shouldmulti-field match中使用nested field match查询。

此外,我想要一个复合评分,其中考虑了其他几个参数,如位置,评级等。

我尝试运行一个简化的概念证明组合查询,它查找匹配的术语并尝试使用其他字段的功能得分,但我遇到了错误。

GET init/restaurant/_search/
{


         "query": { 
           "match": {
           "cuisine_categories": "Oriental"
           },
          "function_score": {
                "functions": [
                  {
                    "gauss": {
                      "coordinates": { 
                        "origin": { "lat": 74.20, "lon": 31.23 },
                        "offset": "1km",
                        "scale":  "3km"
                      }
                    }
                  },
                  {
                    "gauss": {
                      "nomnom_rating": { 
                        "origin": "4.5", 
                        "offset": "0.5",
                        "scale":  "1"
                      }
                    },
                    "weight": 2
                  },
                  {
                    "gauss": {
                      "estimated_preparation_time": {
                        "origin": "30",
                        "offset": "10",
                        "scale": "20"
                      }
                    },
                      "weight": 5
                  }
                ]
              }
            }
}

1 个答案:

答案 0 :(得分:2)

查询无效。 match子句应位于function score的查询对象中,如下所示

示例:

POST init/restaurant/_search/
{
   "query": {
      "function_score": {
         "functions": [
            {
               "gauss": {
                  "coordinates": {
                     "origin": {
                        "lat": 74.2,
                        "lon": 31.23
                     },
                     "offset": "1km",
                     "scale": "3km"
                  }
               }
            },
            {
               "gauss": {
                  "nomnom_rating": {
                     "origin": "4.5",
                     "offset": "0.5",
                     "scale": "1"
                  }
               },
               "weight": 2
            },
            {
               "gauss": {
                  "estimated_preparation_time": {
                     "origin": "30",
                     "offset": "10",
                     "scale": "20"
                  }
               },
               "weight": 5
            }
         ],
         "query": {
            "match": {
               "cuisine_categories": "Oriental"
            }
         }
      }
   }
}