我使用漫威插件创建了这个测试索引:
POST /test
{
"index" : {
"analysis" : {
"analyzer" : {
"folding": {
"tokenizer": "standard",
"filter": [ "lowercase", "asciifolding" ]
}
}
}
}
}
我正在制作这样的分析请求:
GET /test/_analyze?analyzer=folding&text=olá
我得到了结果:
{
"tokens": [
{
"token": "ol",
"start_offset": 0,
"end_offset": 2,
"type": "<ALPHANUM>",
"position": 1
}
]
}
但我需要一个&#34; ola&#34;令牌而不是&#34; ol&#34;只要。根据文档的正确配置:
https://www.elastic.co/guide/en/elasticsearch/guide/current/asciifolding-token-filter.html
我做错了什么?
答案 0 :(得分:8)
试试这个,以证明Elasticsearch最终做得很好。我怀疑Sense接口没有将正确的文本传递给分析器。
PUT /my_index
{
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [ "lowercase", "asciifolding" ]
}
}
}
},
"mappings": {
"test": {
"properties": {
"text": {
"type": "string",
"analyzer": "folding"
}
}
}
}
}
POST /my_index/test/1
{
"text": "olá"
}
GET /my_index/test/_search
{
"fielddata_fields": ["text"]
}
结果:
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "my_indexxx",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"text": "olá"
},
"fields": {
"text": [
"ola"
]
}
}
]
}
答案 1 :(得分:0)
使用更多的recent versions of elasticsearch,您可以像这样通过"asciifolding"
令牌过滤器:
PUT index_name
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
}
}
示例查询:
POST index_name/_analyze
{
"analyzer": "my_analyzer",
"text": "olá"
}
输出:
{
"tokens": [
{
"token": "ola",
"start_offset": 0,
"end_offset": 3,
"type": "<ALPHANUM>",
"position": 0
}
]
}
答案 2 :(得分:0)
上面的示例对我不起作用..经过一些调整,以下示例在Elastic search 7.3.1中起作用:
删除索引(如果以前已创建):
DELETE /my_index
定义索引的映射:
PUT /my_index
{
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"properties": {
"text": {
"type": "text",
"analyzer": "folding",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
添加一些数据:
POST my_index/_doc/1
{"text":"olá"}
执行搜索:
GET /my_index/_search
{
"query": {
"query_string": {
"query": "ola"
}
}
}