elasticsearch - ElasticSearch function_score抛出parsing_exception

标签 elasticsearch elastic-stack querydsl elasticsearch-dsl elasticsearch-query

我在尝试让function_score用于价格字段时遇到麻烦的麻烦。最初,我尝试使用scaled_float字段。但是它不喜欢那样。所以我将价格字段更改为带小数位填充的long字段。因此,我有一个字段为“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
}

关于elasticsearch - ElasticSearch function_score抛出parsing_exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50052731/

相关文章:

docker - 我的Docker无法再使用Elasticsearch

nginx - 使用两个配置文件时的Logstash混合输出

elasticsearch - elasticsearch 允许的最大索引数是多少?

java - 通过使用条件语句和 Java Api 构建 ElasticSearch BoolQuery

elasticsearch - 根据响应值计算Prometheus中的可用性

django - 干草堆中的索引分析器与查询分析器-Elasticsearch?

java - Logstash 加载错误

java - 数组中的 QueryDSL 不区分大小写的过滤器

neo4j - Cypher-QueryDSL : 'My "Q"classes cannot be resolved' compile error (e. g。 Q人)

playframework - QueryDSL 和 Play 框架