如何在弹性搜索中使用过滤项的范围?

时间:2016-11-24 05:45:09

标签: elasticsearch

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)"} []

1 个答案:

答案 0 :(得分:0)

错误字符串表示:

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