如何将大量停用词上传到AWS Elasticsearch?

3

是否可以将 stopwords.txt 上传到 AWS Elasticsearch 并将其指定为停止词令牌过滤器的路径?

3个回答

1

编辑:现在您可以将“包”上传到AWS Elasticsearch服务,这使您可以添加自定义的停用词列表等。请参见https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/custom-packages.html


不,无法将stopwords.txt文件上传到托管的AWS Elasticsearch服务中。您需要在自定义分析器中指定停用词。如何执行此操作的更多详细信息可以在官方文档中找到。
然后官方文档提到“关闭和重新打开”索引,但AWS Elasticsearch不允许这样做,因此您需要重新索引。
例如: 1. 创建一个带有内联列出停用词的自定义分析器的索引,例如:
    PUT /my_new_index
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "english_analyzer": {
              "type": "english", 
              "stopwords": "['a', 'the', 'they', 'and']" 
            }
          }
        }
      }
    }

2. 重新索引

    POST _reindex
    {
      "source": {
        "index": "my_index"
      },
      "dest": {
        "index": "my_new_index"
      }
    }

1
如果您正在使用AWS Elasticsearch,唯一的选项是使用Elasticsearch REST API来完成此操作。
要导入大型数据集,可以使用批量API。

你能提供一些例子来说明如何做吗? - 夏期劇場

0

是的,可以通过在定义停用词过滤器时设置stopwords_path来实现。

stopwords_path => 停用词文件配置的路径(相对于配置位置或绝对路径)。每个停用词应该在自己的“行”中(由换行符分隔)。文件必须使用UTF-8编码。

以下是我是如何做到的。

  1. 将stopwords.txt文件复制到我的elasticsearch主目录下的config文件夹中。
  2. 创建一个自定义的token过滤器,并在stopwords_path中设置路径。 PUT /testindex { "settings": { "analysis": { "filter": { "teststopper": { "type": "stop", "stopwords_path": "stopwords.txt" } } } } }
  3. 使用_analyze API验证过滤器是否按预期工作。 GET testindex/_analyze { "tokenizer" : "standard", "token_filters" : ["teststopper"], "text" : "this is a text to test the stop filter", "explain" : true, "attributes" : ["keyword"] }
  4. 由于我已经将它们添加到config/stopwords.txt文件中,因此标记'a'、'an'、'the'、'to'和'is'被过滤掉了。

更多信息请参见:


1
您无法访问AWS Elasticsearch安装。因此,尽管此解决方案有效,但不适用于上下文中的问题。 - Yeshodhan Kulkarni
我使用亚马逊的elasticsearch服务,但不是AWS ElasticSearch,而是在普通EC2实例中安装了ElasticSearch。因此我的答案基于这个。感谢您的信息,Yeshodhan! - YunujD

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接