Ale*_*x K 2 node.js elasticsearch
大家好,我有这个代码:
let test = await client.search({
index: 'test',
type: 'doc',
body: {
query: {
match: {
title: 'something',
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
此代码通过 1 个查询进行搜索,即 title: 'something' ,但我想将其更改为使用多个键进行搜索,例如:
let test = await client.search({
index: 'test',
type: 'doc',
body: {
query: {
match: {
title: 'something',
desc: 'some Qualifications'
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是这段代码不起作用,我找不到任何可以这样工作的东西,有人可以帮忙吗?
您需要match使用bool/must查询组合所有查询,如下所示:
let test = await client.search({
index: 'test',
type: 'doc',
body: {
query: {
bool: {
must: [
{
match: {
title: 'something',
}
},
{
match: {
desc: 'some Qualifications',
}
}
]
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
773 次 |
| 最近记录: |