Ваш запрос правильный, вам просто нужно убрать флаг "adjust_pure_negative"
или изменить его на false.
Короче говоря, эластик будет "игнорировать" все ваши запросы и просто фильтровать, используя must_not
в случае, если флаг установлен в true. источник
также вы можете удалить boost:1
, поскольку значение по умолчанию равно 1, что делает его избыточным.
РЕДАКТИРОВАТЬ: мой тест
await client.index({index: 'test', id: 5, type: 'test', body: {author: "george", status: "deleted", f1: "v1", f2: "v2"}});
await client.index({index: 'test', id: 6, type: 'test', body: {author: "george", status: "x", f1: "v1",}});
await client.index({index: 'test', id: 7, type: 'test', body: {author: "george", status: "u", f1: "v1", f2: "v2"}});
await client.index({index: 'test', id: 8, type: 'test', body: {author: "george", status: "q", f1: "v1", f4: "v4"}});
await client.index({index: 'test', id: 9, type: 'test', body: {author: "george", status: "1", f3: "v3"}});
let x = await client.search({
index: 'test',
body:
{"size":24,
"query":{
"bool":{
"filter":[{"term":{"author":{"value":"george","boost":1.0}}}],
"must_not":[{"term":{"status":{"value":"deleted","boost":1.0}}}],
"must":[{
"bool":{
"should":[
{"term":{"f1":{"value":"v1","boost":1.0}}},
{"term":{"f2":{"value":"v2","boost":1.0}}},
{"term":{"f3":{"value":"v3","boost":1.0}}},
{"term":{"f4":{"value":"v4","boost":1.0}}}],
"minimum_should_match":"2",
"adjust_pure_negative":false,
"boost":1.0}}
],
"adjust_pure_negative":false,
"boost":1.0}}},
});
результаты: 2 совпадения, как и ожидалось:
[
{
"_index": "test",
"_type": "test",
"_id": "7",
"_score": 0.5753642,
"_source": {
"author": "george",
"status": "u",
"f1": "v1",
"f2": "v2"
}
},
{
"_index": "test",
"_type": "test",
"_id": "8",
"_score": 0.47000366,
"_source": {
"author": "george",
"status": "q",
"f1": "v1",
"f4": "v4"
}
}
]