【问题标题】:Elasticsearch Spanish stemming not working with "rojo" colorElasticsearch 西班牙语词干无法使用“rojo”颜色
【发布时间】:2021-05-28 07:54:14
【问题描述】:

我对 ElasticSearch 还很陌生。我正在尝试分析西班牙语的输入,但颜色“rojo”(西班牙语为红色)似乎存在问题。

根据stemmer demo,字符串“Polera color rojo”(红色衬衫)应该是“poler color roj”,“Polera roja”(红色衬衫)应该是“poler roj”,这样我就可以搜索作为“rojo”或“roja”并获得两个结果。

我在 Kibana 的控制台中使用以下代码初始化了索引:

PUT /test
{
  "settings": {
    "analysis": {
      "filter": {
        "spanish_stop": {
          "type": "stop",
          "stopwords": "_spanish_"
        },
        "spanish_stemmer": {
          "type": "stemmer",
          "language": "spanish"
        }
      },
      "analyzer": {
        "default_search": {
          "type":"spanish",
          "filter": [
            "lowercase",
            "spanish_stop",
            "spanish_stemmer"
          ]
        }
      }
    }
  },
  "mappings":{
    "properties":{
      "fullname":{
        "type":"text",
        "analyzer":"default_search"
      }
    }
  }
}

并使用以下代码进行了查询:

POST /test/_analyze
{
  "analyzer": "default_search",
  "text": "polera color rojo"
}

我收到的回复如下:

{
  "tokens" : [
    {
      "token" : "poler",
      "start_offset" : 0,
      "end_offset" : 6,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "color",
      "start_offset" : 7,
      "end_offset" : 12,
      "type" : "<ALPHANUM>",
      "position" : 1
    },
    {
      "token" : "rojo",
      "start_offset" : 13,
      "end_offset" : 17,
      "type" : "<ALPHANUM>",
      "position" : 2
    }
  ]
}

如您所见,“polera”被正确地称为“poler”,但“rojo”不是。我还尝试了其他颜色和东西,添加更多文本等,但问题似乎与“rojo”有关。

我设法在 AWS 的一个 Elasticsearch 实例和一个本地实例中复制了这个问题。它确实适用于“rojas”和“rojos”等复数形式,而将它们保留为“roj”。

也许我配置有问题,或者实际上是 Elasticsearch 中的西班牙语词干存在问题?

编辑:似乎问题出在字长上? “coma”和“como”也会出现同样的问题,它们应该被称为“com”,但不是。如果我输入“comas”,它就会变成“com”。

【问题讨论】:

    标签: elasticsearch kibana stemming


    【解决方案1】:

    似乎词干分析器类型具有最小标记长度,我尝试使用“rojos”而不是“rojo”,然后将词干转换为“roj”。

    您可以尝试其他方法,例如 Snowball Stemming

    PUT /test_spanish
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "my_analyzer": {
              "tokenizer": "standard",
              "filter": [ "lowercase", "my_snow" ]
            }
          },
          "filter": {
            "my_snow": {
              "type": "snowball",
              "language": "Spanish"
            }
          }
        }
      }
    }
    
    POST /test_spanish/_analyze
    {
      "analyzer": "my_analyzer",
      "text": "polera color rojo"
    }
    
    {
      "tokens" : [
        {
          "token" : "poler",
          "start_offset" : 0,
          "end_offset" : 6,
          "type" : "<ALPHANUM>",
          "position" : 0
        },
        {
          "token" : "color",
          "start_offset" : 7,
          "end_offset" : 12,
          "type" : "<ALPHANUM>",
          "position" : 1
        },
        {
          "token" : "roj",
          "start_offset" : 13,
          "end_offset" : 17,
          "type" : "<ALPHANUM>",
          "position" : 2
        }
      ]
    }
    

    【讨论】:

    • 这解决了它。谢谢!标准词干提取和雪球词干提取之间有什么大的区别吗?
    • @EduardoPérez Snowball 只是算法的名称,因此实现相同的方法不同。有趣的是雪球网站elastic.co/guide/en/elasticsearch/reference/current/…的“stemmer type”西班牙语链接所以我们可以推断出同样的雪球有令牌长度限制(?)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 2013-01-21
    • 2020-10-24
    • 1970-01-01
    • 2017-12-08
    相关资源
    最近更新 更多