我试图向最终用户提供搜索类型,这更像是 sqlserver。
我能够为给定的sql场景实现ES查询:
select * from table where name like '%pete%' and type != 'xyz and type!='abc'
但是ES查询对于这个sql查询不起作用
select * from table where name like '%peter tom%' and type != 'xyz and type!='abc'
在我的弹性搜索以及通配符查询中,我还需要执行一些布尔过滤查询
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"query": {
"wildcard": {
"name": { "value": "*pete*" }
}
}
}
],
"must_not": [
{
"match": { "type": "xyz" }
},
{
"match": { "type": "abc" }
}
]
}
}
}
}
}
上面带有通配符搜索的弹性查询工作正常,并为我提供了所有与 pete 匹配且不是 xyz 和 abc 类型的文档。但是当我尝试使用由空格分隔的 2 个单独单词执行通配符时,相同的查询返回空,如图所示下面。例如
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"query": {
"wildcard": {
"name": { "value": "*peter tom*" }
}
}
}
],
"must_not": [
{
"match": { "type": "xyz" }
},
{
"match": { "type": "abc" }
}
]
}
}
}
}
}
我的映射如下:
{
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
}
我应该使用什么查询才能对以空格分隔的单词进行通配符搜索