ElasticSearch function_score 抛出 parsing_exception

ElasticSearch function_score throwing parsing_exception

我在尝试让 function_score 为价格字段工作时遇到了烦人的麻烦。最初我尝试使用 scaled_float 字段。但是它不喜欢那样。所以我将我的价格字段更改为带有小数位填充的长字段。所以我有一个带有“15000”的字段,价格为 150.00 美元。

这是我对 /products_v7/product/_search

的查询
    {
   "explain":true,
   "query":{
      "function_score":{
         "query":{
            "bool":{
               "should":[
                  {
                     "match_phrase":{
                        "title":{
                           "query":"test",
                           "slop":10
                        }
                     }
                  }
               ]
            }
         },
         "functions":[
            {
               "gauss":{
                  "price":{
                     "origin":"15000",
                     "scale":"2000"
                  }
               },
               "weight":2
            }
         ]
      }
   }
}

这是回复

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "unknown field [price]",
                "line": 1,
                "col": 0
            }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [
            {
                "shard": 0,
                "index": "products_v7",
                "node": "cd3yjjoSSxKxaJ-vCB8SgQ",
                "reason": {
                    "type": "parsing_exception",
                    "reason": "unknown field [price]",
                    "line": 1,
                    "col": 0
                }
            }
        ]
    },
    "status": 400
}

映射 /products_v7/product/_mapping

{
    "products_v7": {
        "mappings": {
            "product": {
                "properties": {
                    "price:": {
                        "type": "long"
                    },
                    "sku": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "title": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        }
    }
}

这是我推送的数据

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 1,
        "hits": [
            {
                "_index": "products_v7",
                "_type": "product",
                "_id": "cSULBGMBog6d8NyO0gRH",
                "_score": 1,
                "_source": {
                    "sku": "126",
                    "title": "test 4",
                    "price:": 15000
                }
            },
            {
                "_index": "products_v7",
                "_type": "product",
                "_id": "fl0FBGMBog0jN_eMK89-",
                "_score": 1,
                "_source": {
                    "sku": "125",
                    "title": "test 3",
                    "price:": 13000
                }
            }
        ]
    }
}

问题是在您的文档中,字段 price 被称为 price:(即名称中有一个冒号。这些细节很重要。

{
     "sku": "126",
     "title": "test 4",
     "price:": 15000
           ^
           |
        see here
}