查询时弹性搜索结果错误(衬衫 --> 短裤)



嗨,伙计们,

我对弹性搜索非常陌生,并试图弄清楚我的查询返回"的原因;错误的";后果当我搜索";衬衫";我的第一个结果是对于具有";短";在名称中。

这是我发送的查询和得到的回复:

请求:

{
"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": []
}
]
}
]
}
},
]
}
}

有什么线索可以说明是什么原因造成的吗?

标准分析器是默认的分析器,它将把T恤分成两个令牌"T";以及";衬衫";。

如果您不想拆分t恤,可以使用空白分析器,当遇到空白时,它会将文本拆分为标记。

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

最新更新