Странная ситуация, связанная с добавлением фильтров к существующему запросу bool.
Этот запрос выводит ровно один результат, один из индекса "pages".Индекс «документы», как и ожидалось, с нашей стороны, имеет нулевые результаты для этого запроса.
Это имеет смысл.Эта версия запроса работает просто отлично.
{
"index": "pages"
}
{
"size": 30,
"query": {
"dis_max": {
"queries": {
"bool": {
"should": [
{
"term": {
"title_exact": "\"this is a test search phrase\""
}
},
{
"query_string": {
"fields": [
"title"
],
"query": "\"this is a test search phrase\""
}
},
{
"nested": {
"path": "versions",
"query": {
"query_string": {
"fields": [
"versions.page_content"
],
"query": "\"this is a test search phrase\""
}
}
}
}
]
}
}
}
}
}
{
"index": "documents"
}
{
"size": 30,
"query": {
"dis_max": {
"queries": {
"bool": {
"should": [
{
"term": {
"title_exact": "\"this is a test search phrase\""
}
},
{
"query_string": {
"fields": [
"title"
],
"query": "\"this is a test search phrase\""
}
},
{
"nested": {
"path": "product.versions",
"query": {
"query_string": {
"fields": [
"versions.page_content"
],
"query": "\"this is a test search phrase\""
}
}
}
}
]
}
}
}
}
}
Однако пользователи имеют возможность добавить фильтр к существующему запросу, в данном случае это продукт.
Это запрос, который отправляется.
{
"index": "pages"
}
{
"size": 30,
"query": {
"dis_max": {
"queries": {
"bool": {
"should": [
{
"term": {
"title_exact": "\"this is a test search phrase\""
}
},
{
"query_string": {
"fields": [
"title"
],
"query": "\"this is a test search phrase\""
}
},
{
"nested": {
"path": "versions",
"query": {
"query_string": {
"fields": [
"versions.page_content"
],
"query": "\"this is a test search phrase\""
}
}
}
}
],
"filter": [
{
"term": {
"product_id": "a2c2c792-84ac-11e8-b4c6-005056a40c60"
}
}
]
}
}
}
}
}
{
"index": "documents"
}
{
"size": 30,
"query": {
"dis_max": {
"queries": {
"bool": {
"should": [
{
"term": {
"title_exact": "\"this is a test search phrase\""
}
},
{
"query_string": {
"fields": [
"title"
],
"query": "\"this is a test search phrase\""
}
},
{
"nested": {
"path": "product.versions",
"query": {
"query_string": {
"fields": [
"versions.page_content"
],
"query": "\"this is a test search phrase\""
}
}
}
}
],
"filter": [
{
"term": {
"product.id": "a2c2c792-84ac-11e8-b4c6-005056a40c60"
}
}
]
}
}
}
}
}
Проблема здесь в том, что, хотя индекс «pages» по-прежнему выдает один желаемый результат, индекс «documents» теперь неожиданно сопоставляется с каждой записью, в которой есть этот идентификатор продукта, и увеличиваетсярезультаты, достижения.
и «фильтр», и «должен» делать одно и то же в этом сценарии.
Честно говоря, он должен давать тот же результат, что и предыдущий запрос.Фильтры должны только уменьшать наборы результатов, а не увеличивать их.
У кого-нибудь есть идеи?
Спасибо