gpt4 book ai didi

elasticsearch - 如何在elasticsearch中使用过滤条件范围?

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

Elasticsearch版本是:5.0

enter image description here

我得到了错误日志:

query_shard_exception: failed to create query:

enter image description here

我的代码有什么问题?

完整日志:
[2016-11-24 14:22:49] request.CRITICAL: Uncaught PHP Exception Elasticsearch\Common\Exceptions\BadRequest400Exception: "query_shard_exception: failed to create query: {   "bool" : {     "must" : [ {       "multi_match" : {         "query" : "射频",         "fields" : [ "description^1.0", "excerpt^1.0", "model^1.0", "title^1.0" ],         "type" : "best_fields",         "operator" : "OR",         "slop" : 0,         "prefix_length" : 0,         "max_expansions" : 50,         "lenient" : false,         "zero_terms_query" : "NONE",         "boost" : 1.0       }     } ],     "filter" : [ {       "range" : {         "most-frequently-used-value" : {           "from" : "40.0",           "to" : null,           "include_lower" : true,           "include_upper" : true,           "boost" : 1.0         }       }     }, {       "term" : {         "radio-frequency-port-connection" : {           "value" : "贴装焊接",           "boost" : 1.0         }       }     } ],     "should" : [ {       "term" : {         "product-type-id" : {           "value" : 1,           "boost" : 1.0         }       }     }, {       "term" : {         "product-type-id" : {           "value" : 2,           "boost" : 1.0         }       }     }, {       "term" : {         "product-type-id" : {           "value" : 3,           "boost" : 1.0         }       }     } ],     "disable_coord" : false,     "adjust_pure_negative" : true,     "boost" : 1.0   } }" at /home/demoer/public_html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php line 682 {"exception":"[object] (Elasticsearch\\Common\\Exceptions\\BadRequest400Exception(code: 400): query_shard_exception: failed to create query: {\n  \"bool\" : {\n    \"must\" : [ {\n      \"multi_match\" : {\n        \"query\" : \"射频\",\n        \"fields\" : [ \"description^1.0\", \"excerpt^1.0\", \"model^1.0\", \"title^1.0\" ],\n        \"type\" : \"best_fields\",\n        \"operator\" : \"OR\",\n        \"slop\" : 0,\n        \"prefix_length\" : 0,\n        \"max_expansions\" : 50,\n        \"lenient\" : false,\n        \"zero_terms_query\" : \"NONE\",\n        \"boost\" : 1.0\n      }\n    } ],\n    \"filter\" : [ {\n      \"range\" : {\n        \"most-frequently-used-value\" : {\n          \"from\" : \"40.0\",\n          \"to\" : null,\n          \"include_lower\" : true,\n          \"include_upper\" : true,\n          \"boost\" : 1.0\n        }\n      }\n    }, {\n      \"term\" : {\n        \"radio-frequency-port-connection\" : {\n          \"value\" : \"贴装焊接\",\n          \"boost\" : 1.0\n        }\n      }\n    } ],\n    \"should\" : [ {\n      \"term\" : {\n        \"product-type-id\" : {\n          \"value\" : 1,\n          \"boost\" : 1.0\n        }\n      }\n    }, {\n      \"term\" : {\n        \"product-type-id\" : {\n          \"value\" : 2,\n          \"boost\" : 1.0\n        }\n      }\n    }, {\n      \"term\" : {\n        \"product-type-id\" : {\n          \"value\" : 3,\n          \"boost\" : 1.0\n        }\n      }\n    } ],\n    \"disable_coord\" : false,\n    \"adjust_pure_negative\" : true,\n    \"boost\" : 1.0\n  }\n} at /home/demoer/public_html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:682, Elasticsearch\\Common\\Exceptions\\BadRequest400Exception(code: 400): {\"error\":{\"root_cause\":[{\"type\":\"query_shard_exception\",\"reason\":\"failed to create query: {\\n  \\\"bool\\\" : {\\n    \\\"must\\\" : [ {\\n      \\\"multi_match\\\" : {\\n        \\\"query\\\" : \\\"射频\\\",\\n        \\\"fields\\\" : [ \\\"description^1.0\\\", \\\"excerpt^1.0\\\", \\\"model^1.0\\\", \\\"title^1.0\\\" ],\\n        \\\"type\\\" : \\\"best_fields\\\",\\n        \\\"operator\\\" : \\\"OR\\\",\\n        \\\"slop\\\" : 0,\\n        \\\"prefix_length\\\" : 0,\\n        \\\"max_expansions\\\" : 50,\\n        \\\"lenient\\\" : false,\\n        \\\"zero_terms_query\\\" : \\\"NONE\\\",\\n        \\\"boost\\\" : 1.0\\n      }\\n    } ],\\n    \\\"filter\\\" : [ {\\n      \\\"range\\\" : {\\n        \\\"most-frequently-used-value\\\" : {\\n          \\\"from\\\" : \\\"40.0\\\",\\n          \\\"to\\\" : null,\\n          \\\"include_lower\\\" : true,\\n          \\\"include_upper\\\" : true,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"radio-frequency-port-connection\\\" : {\\n          \\\"value\\\" : \\\"贴装焊接\\\",\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    } ],\\n    \\\"should\\\" : [ {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 1,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 2,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 3,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    } ],\\n    \\\"disable_coord\\\" : false,\\n    \\\"adjust_pure_negative\\\" : true,\\n    \\\"boost\\\" : 1.0\\n  }\\n}\",\"index_uuid\":\"Hcd6mzy1RjuC6SKnovAdZg\",\"index\":\"dzb-product-data\"}],\"type\":\"search_phase_execution_exception\",\"reason\":\"all shards failed\",\"phase\":\"query\",\"grouped\":true,\"failed_shards\":[{\"shard\":0,\"index\":\"dzb-product-data\",\"node\":\"rC5q8RwqTfK3bYBd8mgqbQ\",\"reason\":{\"type\":\"query_shard_exception\",\"reason\":\"failed to create query: {\\n  \\\"bool\\\" : {\\n    \\\"must\\\" : [ {\\n      \\\"multi_match\\\" : {\\n        \\\"query\\\" : \\\"射频\\\",\\n        \\\"fields\\\" : [ \\\"description^1.0\\\", \\\"excerpt^1.0\\\", \\\"model^1.0\\\", \\\"title^1.0\\\" ],\\n        \\\"type\\\" : \\\"best_fields\\\",\\n        \\\"operator\\\" : \\\"OR\\\",\\n        \\\"slop\\\" : 0,\\n        \\\"prefix_length\\\" : 0,\\n        \\\"max_expansions\\\" : 50,\\n        \\\"lenient\\\" : false,\\n        \\\"zero_terms_query\\\" : \\\"NONE\\\",\\n        \\\"boost\\\" : 1.0\\n      }\\n    } ],\\n    \\\"filter\\\" : [ {\\n      \\\"range\\\" : {\\n        \\\"most-frequently-used-value\\\" : {\\n          \\\"from\\\" : \\\"40.0\\\",\\n          \\\"to\\\" : null,\\n          \\\"include_lower\\\" : true,\\n          \\\"include_upper\\\" : true,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"radio-frequency-port-connection\\\" : {\\n          \\\"value\\\" : \\\"贴装焊接\\\",\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    } ],\\n    \\\"should\\\" : [ {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 1,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 2,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 3,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    } ],\\n    \\\"disable_coord\\\" : false,\\n    \\\"adjust_pure_negative\\\" : true,\\n    \\\"boost\\\" : 1.0\\n  }\\n}\",\"index_uuid\":\"Hcd6mzy1RjuC6SKnovAdZg\",\"index\":\"dzb-product-data\",\"caused_by\":{\"type\":\"number_format_exception\",\"reason\":\"For input string: \\\"40.0\\\"\"}}}],\"caused_by\":{\"type\":\"query_shard_exception\",\"reason\":\"failed to create query: {\\n  \\\"bool\\\" : {\\n    \\\"must\\\" : [ {\\n      \\\"multi_match\\\" : {\\n        \\\"query\\\" : \\\"射频\\\",\\n        \\\"fields\\\" : [ \\\"description^1.0\\\", \\\"excerpt^1.0\\\", \\\"model^1.0\\\", \\\"title^1.0\\\" ],\\n        \\\"type\\\" : \\\"best_fields\\\",\\n        \\\"operator\\\" : \\\"OR\\\",\\n        \\\"slop\\\" : 0,\\n        \\\"prefix_length\\\" : 0,\\n        \\\"max_expansions\\\" : 50,\\n        \\\"lenient\\\" : false,\\n        \\\"zero_terms_query\\\" : \\\"NONE\\\",\\n        \\\"boost\\\" : 1.0\\n      }\\n    } ],\\n    \\\"filter\\\" : [ {\\n      \\\"range\\\" : {\\n        \\\"most-frequently-used-value\\\" : {\\n          \\\"from\\\" : \\\"40.0\\\",\\n          \\\"to\\\" : null,\\n          \\\"include_lower\\\" : true,\\n          \\\"include_upper\\\" : true,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"radio-frequency-port-connection\\\" : {\\n          \\\"value\\\" : \\\"贴装焊接\\\",\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    } ],\\n    \\\"should\\\" : [ {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 1,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 2,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    }, {\\n      \\\"term\\\" : {\\n        \\\"product-type-id\\\" : {\\n          \\\"value\\\" : 3,\\n          \\\"boost\\\" : 1.0\\n        }\\n      }\\n    } ],\\n    \\\"disable_coord\\\" : false,\\n    \\\"adjust_pure_negative\\\" : true,\\n    \\\"boost\\\" : 1.0\\n  }\\n}\",\"index_uuid\":\"Hcd6mzy1RjuC6SKnovAdZg\",\"index\":\"dzb-product-data\",\"caused_by\":{\"type\":\"number_format_exception\",\"reason\":\"For input string: \\\"40.0\\\"\"}}},\"status\":400} at /home/demoer/public_html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:681)"} []

最佳答案

错误字符串表示:

"type":"number_format_exception",
"reason":"For input string: "40.0""}}}

试试这个 range查询
{
"range": {
"most-frequently-used-value": {
"from": 40, <--- change this
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}

关于elasticsearch - 如何在elasticsearch中使用过滤条件范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40778815/

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