【问题标题】:ElasticSearch combine match and function score queriesElasticSearch 结合了匹配和函数得分查询
【发布时间】:2015-08-12 20:32:43
【问题描述】:

我有一个复杂的查询要在跨多个字段(嵌套和非嵌套)的 elasticsearch 中运行。我在multi-field matchnested field match 中使用bool should 查询。

另外,我想要一个综合评分,它考虑到其他几个参数,例如位置、评级等。

我尝试运行一个简化的概念证明组合查询,它查找匹配项并尝试对其他字段使用函数分数,但我遇到了来自 es 的错误。

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
                  }
                ]
              }
            }
}

【问题讨论】:

    标签: indexing elasticsearch lucene


    【解决方案1】:

    查询无效。 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"
                }
             }
          }
       }
    }
    

    【讨论】:

    • 您的查询出现“预期的字段名称,但有一个起始对象”异常。
    • 救命稻草!适用于一切,
    猜你喜欢
    • 2017-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多