【发布时间】:2021-08-15 13:58:18
【问题描述】:
所以我有一个大约 60GB 数据的索引,基本上我想根据参考号进行查询以检索 1 个特定产品。
这是我的查询:
GET myindex/_search
{
"_source": [
"product.ref",
"product.urls.*",
"product.i18ns.*.title",
"product_sale_elements.quantity",
"product_sale_elements.prices.*.price",
"product_sale_elements.listen_price.*",
"product.images.image_url",
"product.image_count",
"product.images.visible",
"product.images.position"
],
"size": "6",
"from": "0",
"query": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field": "product.sales_count",
"missing": 0,
"modifier": "log1p"
}
},
{
"field_value_factor": {
"field": "product.image_count",
"missing": 0,
"modifier": "log1p"
}
},
{
"field_value_factor": {
"field": "featureCount",
"missing": 0,
"modifier": "log1p"
}
}
],
"query": {
"bool": {
"filter": [
{
"term": {
"product.is_visible": true
}
}
],
"should": [
{
"query_string": {
"default_field": "product.ref",
"query": "13141000",
"boost": 2
}
}
]
}
}
}
},
"aggs": {
"by_categories": {
"terms": {
"field": "categories.i18ns.de_DE.title.raw",
"size": 100
}
}
}
}
因此,我的问题是,为什么这个查询会返回 10k 个结果,而我只想要具有该参考号的 1 个单一产品。
如果我这样做:
GET my-index/_search
{
"query": {
"match": {
"product.ref": "13141000"
}
}
}
匹配正确。 should 与普通的 match 查询有何不同?
【问题讨论】:
-
为什么要在
should中加上product.ref的约束?如果必须匹配,则需要进入filter数组
标签: elasticsearch lucene matching booleanquery