【发布时间】:2018-07-27 14:02:50
【问题描述】:
我的查询很简单,为了更简单,假设我只搜索两个字段,名称(文本)和年龄(长):
GET person_db/person/_search
{
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": {
"name": "hank"
}
},
{
"match_phrase_prefix": {
"age": "hank"
}
}
],
"minimum_should_match": 1,
"boost": 1.0
}
}
}
如果我搜索“23”,没问题,elastic 知道如何将其更改为数字并且不会失败,但如果搜索输入为“john”,我会收到错误 400 "reason": "failed to create query: {\n \"bool\...."。
在这种情况下我该怎么办?
我想过在insert到es之前把数值型的值改成字符串,但是尽量避免,我觉得es应该有办法支持。
欣赏
此查询有效:(感谢@jmlw)
{
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "alt",
"type": "phrase_prefix",
"fields": [
"name",
"taxid",
"providers.providerAddress.street"
],
"lenient": true
}
}
],
"minimum_should_match": 1,
"boost": 1.0
}
}
}
【问题讨论】:
-
你能添加完整的错误吗?我怀疑 Es 不喜欢在数字字段中搜索文本值...
-
@Val 是的,我很确定,但是我该如何解决呢?当我构建查询时,我将客户端输入放在所有字段中......我不知道输入将是什么
-
您可以尝试使用两个字段而不是单独的
match_phrase_prefix子句来执行multi_matchof typephrase_prefix吗?
标签: elasticsearch elasticsearch-5 elasticsearch-aggregation