查询中的ElasticSearch结果错误(衬衫-->短裤)

ygya80vv  于 2022-11-02  发布在  ElasticSearch
关注(0)|答案(1)|浏览(136)

嘿伙计们,
我对ElasticSearch非常陌生,并试图找出我的查询返回“错误”结果的原因。当我搜索“衬衫”时,我的第一个结果是名称中带有“短”的产品。
下面是我发送的查询和得到的响应:
请求:

{
    "explain": true,
    "size": 3,
    "query": {
        "bool": {
            "filter": {
                "bool": {
                    "must": [
                        {
                            "terms": {
                                "visibility": [
                                    3,
                                    4
                                ]
                            }
                        },
                        {
                            "terms": {
                                "status": [
                                    0,
                                    1
                                ]
                            }
                        },
                        {
                            "terms": {
                                "stock.is_in_stock": [
                                    true
                                ]
                            }
                        }
                    ]
                }
            },
            "must": {
                "function_score": {
                    "functions": [
                        {
                            "filter": {
                                "match": {
                                    "attribute_code": "attribute_value"
                                }
                            },
                            "weight": 1
                        }
                    ],
                    "score_mode": "multiply",
                    "boost_mode": "multiply",
                    "max_boost": 100,
                    "min_score": 1,
                    "query": {
                        "bool": {
                            "should": [
                                {
                                    "multi_match": {
                                        "fields": [
                                            "name^2",
                                            "sku^50",
                                            "category.name^1"
                                        ],
                                        "query": "shirt",
                                        "operator": "or",
                                        "fuzziness": 2,
                                        "cutoff_frequency": 0.01,
                                        "max_expansions": 3,
                                        "prefix_length": 2,
                                        "minimum_should_match": "75%",
                                        "tie_breaker": "1"
                                    }
                                },
                                {
                                    "bool": {
                                        "should": [
                                            {
                                                "terms": {
                                                    "configurable_children.sku": [
                                                        "shirt"
                                                    ]
                                                }
                                            },
                                            {
                                                "match_phrase": {
                                                    "sku": {
                                                        "query": "shirt",
                                                        "boost": 1
                                                    }
                                                }
                                            },
                                            {
                                                "match_phrase": {
                                                    "configurable_children.sku": {
                                                        "query": "shirt",
                                                        "boost": 1
                                                    }
                                                }
                                            }
                                        ]
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        }
    }
}

部分回应:

{
    "took": 6,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 3,
            "relation": "eq"
        },
        "max_score": 10.345283,
        "hits": [
            {
                "_shard": "[vue_storefront_catalog_1_product_1666220454][0]",
                "_node": "fM1XenujQqO0VZKK3bAdVw",
                "_index": "vue_storefront_catalog_1_product_1666220454",
                "_type": "product",
                "_id": "37522",
                "_score": 10.345283,
                "_source": {
                    ...
                    "name": "MISAKI PENDANT W IDYLL SHORT",
                    "image": "/7/4/74202_2_1_1_1.jpg",
                    "small_image": "/7/4/74202_2_1_1_1.jpg",
                    "thumbnail": "/7/4/74202_2_1_1_1.jpg",
                    "msrp_display_actual_price_type": "0",
                    "url_key": "misaki-pendant-w-idyll-short-37522",
                    ...
                    "attributes_metadata": []
                },
                "_explanation": {
                    "value": 10.345283,
                    "description": "sum of:",
                    "details": [
                        {
                            "value": 10.345283,
                            "description": "function score, product of:",
                            "details": [
                                {
                                    "value": 10.345283,
                                    "description": "sum of:",
                                    "details": [
                                        {
                                            "value": 10.345283,
                                            "description": "sum of:",
                                            "details": [
                                                {
                                                    "value": 10.345283,
                                                    "description": "weight(name:short in 16444) [PerFieldSimilarity], result of:",
                                                    "details": [
                                                        {
                                                            "value": 10.345283,
                                                            "description": "score(freq=1.0), computed as boost * idf * tf from:",
                                                            "details": [
                                                                {
                                                                    "value": 3.5200002,
                                                                    "description": "boost",
                                                                    "details": []
                                                                },
                                                                {
                                                                    "value": 6.939326,
                                                                    "description": "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
                                                                    "details": [
                                                                        {
                                                                            "value": 13,
                                                                            "description": "n, number of documents containing term",
                                                                            "details": []
                                                                        },
                                                                        {
                                                                            "value": 13932,
                                                                            "description": "N, total number of documents with field",
                                                                            "details": []
                                                                        }
                                                                    ]
                                                                },
                                                                {
                                                                    "value": 0.42352825,
                                                                    "description": "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
                                                                    "details": [
                                                                        {
                                                                            "value": 1.0,
                                                                            "description": "freq, occurrences of term within document",
                                                                            "details": []
                                                                        },
                                                                        {
                                                                            "value": 1.2,
                                                                            "description": "k1, term saturation parameter",
                                                                            "details": []
                                                                        },
                                                                        {
                                                                            "value": 0.75,
                                                                            "description": "b, length normalization parameter",
                                                                            "details": []
                                                                        },
                                                                        {
                                                                            "value": 5.0,
                                                                            "description": "dl, length of field",
                                                                            "details": []
                                                                        },
                                                                        {
                                                                            "value": 4.2408123,
                                                                            "description": "avgdl, average length of field",
                                                                            "details": []
                                                                        }
                                                                    ]
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "value": 1.0,
                                    "description": "min of:",
                                    "details": [
                                        {
                                            "value": 1.0,
                                            "description": "No function matched",
                                            "details": []
                                        },
                                        {
                                            "value": 100.0,
                                            "description": "maxBoost",
                                            "details": []
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "value": 0.0,
                            "description": "match on required clause, product of:",
                            "details": [
                                {
                                    "value": 0.0,
                                    "description": "# clause",
                                    "details": []
                                },
                                {
                                    "value": 1.0,
                                    "description": "#visibility:{3 4} #status:{0 1} #ConstantScore(stock.is_in_stock:T)",
                                    "details": []
                                }
                            ]
                        }
                    ]
                }
            },
        ]
    }
}

有什么线索能说明这是什么原因吗?

2w3rbyxf

2w3rbyxf1#

标准分析器(默认分析器)将T恤拆分为两个标记“T”和“shirt”。
如果不想拆分T恤,可以使用whitespace analyzer,当遇到空格时,它会将文本拆分为标记。

"settings":{
  "analysis": {
    "analyzer": {
      "lowercasewhitespaceanalyzer": {
        "type": "custom",
        "tokenizer": "whitespace",
        "filter": [
          "lowercase"
        ]
      }
    }
  }
},
"mappings": {
    "properties": {
      "title": {
        "type": "text",
        "analyzer": "lowercasewhitespaceanalyzer"
      }
    }
  }

相关问题