Pab*_*dro 3 elasticsearch elasticsearch-plugin
我正在使用 ElasticSearch,我想进行查询。
我有不同的模块:['a', 'b', 'c', 'd']. 其中a和 b有一个额外的值 ( companyId) 我需要过滤所有模块的文本,但我需要过滤companyIdjust fora和bnot for 模块c和d。
这看起来像这样:
SELECT * FROM my_table WHERE (modules in ('a', 'b') and companyId='myid') OR (modules in ('b', 'c'))
但我有这个:
client.search({
index: INDEX,
type: TYPE,
body: {
query: {
bool: {
must: {
match: { text: 'mytext' },
},
filter: [
{ terms: { module: ['a', 'b', 'c', 'd'] } },
{ term: { companyId: 'myid' } },
]
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
如果您能提供帮助,非常感谢。
以下查询就是您要查找的内容。我已经在里面实现了OR运算符 ieshouldfilter
{
"query": {
"bool": {
"must": {
"match": { "text": "mytext" }
},
"filter": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{ "match": { "module": "a" }},
{ "match": { "companyId": "1" }}
]
}
},
{
"bool": {
"must": [
{ "match": { "module": "b" }},
{ "match": { "companyId": "1" }}
]
}
},
{
"bool": {
"must": {
"match": { "module": "c" }
}
}
},
{
"bool": {
"must": {
"match": { "module": "d" }
}
}
}
]
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17476 次 |
| 最近记录: |