elasticsearch转义特殊字符
elasticseach escape special characters
我是运行下面的查询
GET myindex/my_type/_search
{
"query": {
"query_string": {
"default_field": "campaign_new",
"query": "(firtPart - Second Third)"
}
}
}
我得到
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
但是,如果我进行 match_all 搜索,我有此广告系列的值,但此查询未获取它。我怀疑这可能是由于转义问题造成的。但是当我尝试 firtPart \- Second\ Third
时,它在 Sense 中显示错误。
你需要两次转义。我假设您正在尝试进行精确匹配,因此您只需要将查询用双引号括起来,双引号也需要转义(引号只需要转义一次)。
{
"query": {
"query_string": {
"default_field": "campaign_new",
"query": "\"(firtPart - Second Third)\""
}
}
}
我是运行下面的查询
GET myindex/my_type/_search
{
"query": {
"query_string": {
"default_field": "campaign_new",
"query": "(firtPart - Second Third)"
}
}
}
我得到
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
但是,如果我进行 match_all 搜索,我有此广告系列的值,但此查询未获取它。我怀疑这可能是由于转义问题造成的。但是当我尝试 firtPart \- Second\ Third
时,它在 Sense 中显示错误。
你需要两次转义。我假设您正在尝试进行精确匹配,因此您只需要将查询用双引号括起来,双引号也需要转义(引号只需要转义一次)。
{
"query": {
"query_string": {
"default_field": "campaign_new",
"query": "\"(firtPart - Second Third)\""
}
}
}