我正在尝试构建一个查询,在该查询中,我可以接受包含字符串和数字的字符串,并在我的索引中包含双精度值和字符串的字段中搜索这些值。例如:
字段: Double doubleVal,String stringVal0,String stringVal1,String doNotSearchVal
示例搜索字符串:"person 10“
我正在尝试获取在doubleVal、stringVal0和stringVal1字段中包含"person“或"10”的所有文档。这是我的示例查询:
{
"query": {
"multi_match" : {
"query": "person 10",
"fields" : [
"doubleVal^1.0",
"stringVal0^1.0",
"stringVal1^1.0"
],
"type" : "best_fields",
"operator" : "OR",
"slop" : 0,
"prefix_length" : 0,
"max_expansions" : 50,
"zero_terms_query" : "NONE",
"auto_generate_synonyms_phrase_query" : true,
"fuzzy_transpositions" : true,
"boost" : 1.0
}
}
}(此查询由Spring Data Elastic生成)
当我运行这个查询时,我得到这个错误:(我已经删除了所有标识信息)
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: [query removed]",
"index_uuid": "index_uuid",
"index": "index_name"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "index_name",
"node": "node_value",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: [query removed]",
"index_uuid": "index_uuid",
"index": "index_name",
"caused_by": {
"type": "number_format_exception",
"reason": "For input string: \"person 10\""
}
}
}
]
},
"status": 400
}我不想拆分搜索字符串。如果有一种方法可以重写查询,使其以预期的方式工作,我愿意这样做。
发布于 2019-10-14 02:54:02
应尝试将参数lenient设置为true,然后将忽略基于格式的错误,例如为数值字段提供文本查询值
您可以在Spring Data中使用下面这样的builder方法来实现这一点:
.lenient(true)
https://stackoverflow.com/questions/58349538
复制相似问题