弹性搜索映射分析器 - 获取不到结果 [英] elasticsearch mapping analyzer - GET not getting result

查看:208
本文介绍了弹性搜索映射分析器 - 获取不到结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个分析器,用一个空格代替特殊字符并将其转换为大写。然后,如果我想用小写搜索也应该工作。

I am trying to create an analyzer, which replaces special character with a whitespace and convert it into uppercase. then after, if I want to search with lowercase also it should work.

映射分析器:

soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XPUT 'http://localhost:9200/aida' -d '{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "char_filter": [
            "my_char_filter"
          ],
          "filter": [
            "uppercase"
            ]
        }
      },
      "char_filter": {
        "my_char_filter": {
          "type": "pattern_replace",
          "pattern": "(\\d+)-(?=\\d)",
          "replacement": "$1 "
        }
      }
    }
  }
}
'
{"acknowledged":true}


soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XPOST 'http://localhost:9200/aida/_analyze?pretty' -d '{
"analyzer":"my_analyzer",
"text":"My name is Soun*arya?jwnne&yuuk"
}'

通过将特殊字符替换为空格来正确标记字词。现在,如果我从文本中搜索一个单词,它不会检索任何结果。

It is tokenizing the words properly by replacing the special character with the whitespace. Now if I search a word from the text, it is not retrieving me any result.

soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XGET 'http://localhost:9200/aida/_search' -d '{
"query":{
"match":{
"text":"My"
}
}
}'

我没有从上述GET查询中得到任何结果。获取结果如下:

I am not getting any result out of the above GET query. Getting result like :

soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XGET 'http://localhost:9200/aida/_search' -d '{
"query":{
"match":{
"text":"my"
}
}
}'
{"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

任何人都可以帮我这个!谢谢!

Can anyone help me with this! Thank you!

推荐答案

创建索引后,似乎没有索引任何数据。调用 _analyze 将不会对任何内容进行索引,而只是向您展示如何分析发送给ES的内容。

You don't seem to have indexed any data after creating your index. The call to _analyze will not index anything but simply show you how the content you send to ES would be analyzed.

首先,您需要通过指定使用您定义的分析器的映射来创建索引:

First, you need to create your index by specifying a mapping in which you use the analyzer you've defined:

curl -XPUT 'http://localhost:9200/aida' -d '{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "standard",
          "char_filter": [
            "my_char_filter"
          ],
          "filter": [
            "uppercase"
            ]
        }
      },
      "char_filter": {
        "my_char_filter": {
          "type": "pattern_replace",
          "pattern": "(\\d+)-(?=\\d)",
          "replacement": "$1 "
        }
      }
    }
  },
  "mappings": {                        <--- add a mapping type...
    "doc": {
      "properties": {
        "text": {                      <--- ...with a field...
          "type": "string",
          "analyzer": "my_analyzer"    <--- ...using your analyzer
        }
      }
    }
  }
}'

然后,您可以索引一个新的真实文档:

Then you can index a new real document:

curl -XPOST 'http://localhost:9200/aida/doc' -d '{
   "text": "My name is Soun*arya?jwnne&yuuk"
}'

最后,您可以搜索:

curl -XGET 'http://localhost:9200/aida/_search' -d '{
  "query":{
    "match":{
      "text":"My"
    }
  }
}'

这篇关于弹性搜索映射分析器 - 获取不到结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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