本文介绍了如何在 elasticsearch 中设置分词器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 elasticsearch-jetty 项目的嵌入式 elasticsearch,我需要设置为使用比默认值更好的标记器.我想使用关键字标记器.

I have an embedded elasticsearch using the elasticsearch-jetty project, and I need to setup to use tokenizers better than the defaults. I want to use the keyword tokenizer.

我一生都无法弄清楚如何通过配置文件来做到这一点.任何人都可以通过配置文件指出我的方法吗?

I can't figure out for the life of me how to do this through the config files. Can anyone point me at a way to do this through config files?

顺便说一句,是否可以通过对索引执行 POST 来在索引启动和运行时调整索引?我真的很想了解如何使用它,谢谢.

As an aside, is it possible to adjust the index while it's up and running by doing a POST to the index? I'd really like to understand how to use this, thank you.

编辑/更新:我在运行 curl -XPUT 或 -XPOST 到 localhost:9200 时遇到问题,试图调整我在此处搜索帮助时看到的一些示例/论坛中的设置,我得到了结果'没有处理程序用于 uri [] 和方法 [PUT]/[POST].

EDIT/update: I'm having trouble running curl -XPUT or -XPOST to localhost:9200 to try to adjust settings from some of the examples/forums I've seen when searching to help here, I'm getting results of 'No handler for uri [] and method [PUT]/[POST].

编辑 2:更新,对索引执行 XPUT 工作,但我收到有关索引已存在"的错误消息.我知道它存在,我想更新它.

EDIT 2: Update, doing XPUT to an index works, but I get an error about "Index already exists". I know it exists, I want to update it.

推荐答案

您可以在配置文件中定义映射,但在大多数情况下,通过 API 进行配置更容易/更灵活.例如,此命令将在索引 test 中添加关键字/小写分析器:

You can define mappings in the config files, but for most cases it is easier/more flexible to configure through the API. For example, this command will add a keyword/lowercase analyzer to the index test:

$ curl -XPUT localhost:9200/testindex/ -d '
{
  "settings":{
     "index":{
        "analysis":{
           "analyzer":{
              "analyzer_keyword":{
                 "tokenizer":"keyword",
                 "filter":"lowercase"
              }
           }
        }
     }
  },
  "mappings":{
     "test":{
        "properties":{
           "title":{
              "analyzer":"analyzer_keyword",
              "type":"string"
           }
        }
     }
  }
}'

这篇关于如何在 elasticsearch 中设置分词器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:55