【问题标题】:ElasticSearch match scoreElasticSearch 匹配分数
【发布时间】:2017-04-11 10:18:39
【问题描述】:

我的索引中有一个“文本”类型的简单字段。

"keywordName": {
          "type": "text"
        }

我已经插入了这些文件:“三星”、“三星银河”、“三星封面”、“三星充电器”。

如果我进行简单的“匹配”查询,结果令人不安:

查询:

GET keywords/_search
{
  "query": {
    "match": {
      "keywordName": "samsung"
    }
  }
}

结果:

{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 4,
    "max_score": 1.113083,
    "hits": [
      {
        "_index": "keywords",
        "_type": "keyword",
        "_id": "samsung galaxy",
        "_score": 1.113083,
        "_source": {
          "keywordName": "samsung galaxy"
        }
      },
      {
        "_index": "keywords",
        "_type": "keyword",
        "_id": "samsung charger",
        "_score": 0.9433406,
        "_source": {
          "keywordName": "samsung charger"
        }
      },
      {
        "_index": "keywords",
        "_type": "keyword",
        "_id": "samsung",
        "_score": 0.8405092,
        "_source": {
          "keywordName": "samsung"
        }
      },
      {
        "_index": "keywords",
        "_type": "keyword",
        "_id": "samsung cover",
        "_score": 0.58279467,
        "_source": {
          "keywordName": "samsung cover"
        }
      }
    ]
  }
}

第一个问题:为什么“三星”没有最高分?

第二个问题:如何进行查询或分析,让我获得“三星”作为最高分?

【问题讨论】:

  • 你问的问题基本上和stackoverflow.com/questions/43257656/…一样。第一个问题的答案是elastic.co/guide/en/elasticsearch/guide/current/…。你的第二个问题的答案是我已经回复过的另一个帖子。
  • 问题完全一样,但是如果我使用与其他索引相同的索引和分析器,并且搜索“samsungs”,则标记为“samsung”,因此术语查询不起作用&匹配查询返回“三星银河”...
  • 这就是为什么在开始为您的索引和针对这些要求的查询列表进行映射之前,先列出所有要求很重要的原因。

标签: elasticsearch match token keyword


【解决方案1】:

从与我的previous reply 相同的索引设置(分析器、过滤器、映射)开始,我建议采用以下解决方案。但是,正如我所提到的,您需要根据需要在此索引中搜索的内容制定所有要求,并将所有这些视为一个完整的解决方案。

DELETE test
PUT test
{
  "settings": {
    "analysis": {
      "analyzer": {
        "custom_stop": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": [
            "my_stop",
            "my_snow",
            "asciifolding"
          ]
        }
      },
      "filter": {
        "my_stop": {
          "type": "stop",
          "stopwords": "_french_"
        },
        "my_snow": {
          "type": "snowball",
          "language": "French"
        }
      }
    }
  },
  "mappings": {
    "test": {
      "properties": {
        "keywordName": {
          "type": "text",
          "analyzer": "custom_stop",
          "fields": {
            "raw": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}
POST /test/test/_bulk
{"index":{}}
{"keywordName":"samsung galaxy"}
{"index":{}}
{"keywordName":"samsung charger"}
{"index":{}}
{"keywordName":"samsung cover"}
{"index":{}}
{"keywordName":"samsung"}

GET /test/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "keywordName": {
              "query": "samsungs",
              "operator": "and"
            }
          }
        },
        {
          "term": {
            "keywordName.raw": {
              "value": "samsungs"
            }
          }
        },
        {
          "fuzzy": {
            "keywordName.raw": {
              "value": "samsungs",
              "fuzziness": 1
            }
          }
        }
      ]
    }
  },
  "size": 10
}

【讨论】:

  • 我同意你的要求。问题是在我的情况下它有点进化。我没有完整批次的数据,设置详尽的需求列表是一个相当大的问题。
猜你喜欢
  • 2018-03-17
  • 1970-01-01
  • 2016-10-10
  • 2013-09-11
  • 2019-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-02
相关资源
最近更新 更多