如何在弹性搜索中设置标记器 [英] How to setup a tokenizer in elasticsearch

查看:142
本文介绍了如何在弹性搜索中设置标记器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用elasticsearch-jetty项目的嵌入式弹性搜索,我需要设置比默认值更好地使用tokenizer。我想使用关键字tokenizer。



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



除此之外,可以通过对索引执行POST来调整索引,同时启动和运行索引?我真的很想了解如何使用这个,谢谢。



编辑/更新:我无法将curl -XPUT或-XPOST运行到localhost:9200,以尝试从我所拥有的一些示例/论坛中调整设置在搜索帮助的时候看到,我得到'没有处理程序的uri []和方法[PUT] / [POST]的结果。



编辑2:更新,做一个索引的XPUT工作,但是我收到一个关于索引已经存在的错误。我知道它存在,我想更新它。

解决方案

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

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


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?

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.

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].

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.

解决方案

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"
           }
        }
     }
  }
}'

这篇关于如何在弹性搜索中设置标记器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆