gpt4 book ai didi

elasticsearch - ElasticSearch function_score抛出parsing_exception

转载 作者:行者123 更新时间:2023-12-03 00:53:08 25 4
gpt4 key购买 nike

我在尝试让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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com