ES分词器 Analyzer

2020-02-01  本文已影响0人  鸿雁长飞光不度

1.Analysis和Analyzer

2. Analyzer组成

分词案例:

[Mastering Elastersearch & Elastersearch in Action] =>
[Character Filters] =>[Tokenizer] => [Token Filter]
=> (master,elastersaerch,action)

3._analyzer API

可以查看分词器是如何工作的

GET /_analyze
{
  "analyzer": "standard",
  "text": "China is a great counrty"
}
{
  "tokens" : [
    {
      "token" : "china",
      "start_offset" : 0,
      "end_offset" : 5,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "is",
      "start_offset" : 6,
      "end_offset" : 8,
      "type" : "<ALPHANUM>",
      "position" : 1
    },
    {
      "token" : "a",
      "start_offset" : 9,
      "end_offset" : 10,
      "type" : "<ALPHANUM>",
      "position" : 2
    },
    {
      "token" : "great",
      "start_offset" : 11,
      "end_offset" : 16,
      "type" : "<ALPHANUM>",
      "position" : 3
    },
    {
      "token" : "counrty",
      "start_offset" : 17,
      "end_offset" : 24,
      "type" : "<ALPHANUM>",
      "position" : 4
    }
  ]
}
POST users/_analyze
{
  "field": "account",
  "text":"中国是伟大的国家"
}
POST /_analyze
{
  "tokenizer": "standard", 
  "filter": ["uppercase"], 
  "text": ["I am Chinese","Made in China"]
}

3. 常用分词器

https://www.elastic.co/guide/en/elasticsearch/reference/7.3/analysis-analyzers.html

GET /_analyze
{
  "analyzer": "pattern",
  "text": "China is a great counrty"
}
GET /_analyze
{
  "analyzer": "icu_analyzer",
  "text": "她说的的确在理"
}
{
  "tokens" : [
    {
      "token" : "她",
      "start_offset" : 0,
      "end_offset" : 1,
      "type" : "<IDEOGRAPHIC>",
      "position" : 0
    },
    {
      "token" : "说的",
      "start_offset" : 1,
      "end_offset" : 3,
      "type" : "<IDEOGRAPHIC>",
      "position" : 1
    },
    {
      "token" : "的确",
      "start_offset" : 3,
      "end_offset" : 5,
      "type" : "<IDEOGRAPHIC>",
      "position" : 2
    },
    {
      "token" : "在",
      "start_offset" : 5,
      "end_offset" : 6,
      "type" : "<IDEOGRAPHIC>",
      "position" : 3
    },
    {
      "token" : "理",
      "start_offset" : 6,
      "end_offset" : 7,
      "type" : "<IDEOGRAPHIC>",
      "position" : 4
    }
  ]
}
上一篇 下一篇

猜你喜欢

热点阅读