Elasticsearch之Analyze(分析过程)

_analyze是Elasticsearch一个非常有用的API,它可以帮助你分析每一个field或者某个analyzer/tokenizer是如何分析和索引一段文字。
返回结果字段含义:
token是一个实际被存储在索引中的词
position指明词在原文本中是第几个出现的
start_offset和end_offset表示词在原文本中占据的位置。
1、默认analyzer
GET /_analyze?
{"analyzer" : "standard",  "text" : "床前明月光"}
{
  "tokens": [
    {
      "token": "床",
      "start_offset": 0,
      "end_offset": 1,
      "type": "<IDEOGRAPHIC>",
      "position": 0
    },
    {
      "token": "前",
      "start_offset": 1,
      "end_offset": 2,
      "type": "<IDEOGRAPHIC>",
      "position": 1
    },
    {
      "token": "明",
      "start_offset": 2,
      "end_offset": 3,
      "type": "<IDEOGRAPHIC>",
      "position": 2
    },
    {
      "token": "月",
      "start_offset": 3,
      "end_offset": 4,
      "type": "<IDEOGRAPHIC>",
      "position": 3
    },
    {
      "token": "光",
      "start_offset": 4,
      "end_offset": 5,
      "type": "<IDEOGRAPHIC>",
      "position": 4
    }
  ]
}
2、也可以用指定的analyzer来分析使用whitspace
GET /_analyze?
{
  "analyzer" : "whitespace",
  "text" : "床前 明月光"
}


{
  "tokens": [
    {
      "token": "床前",
      "start_offset": 0,
      "end_offset": 2,
      "type": "word",
      "position": 0
    },
    {
      "token": "明月光",
      "start_offset": 3,
      "end_offset": 6,
      "type": "word",
      "position": 1
    }
  ]
}
3、使用ik分析器
GET /tystock/_analyze?
{
  "analyzer": "ik_max_word",
  "text" : "床前明月光"
}
{
  "tokens": [
    {
      "token": "床前明月光",
      "start_offset": 0,
      "end_offset": 5,
      "type": "CN_WORD",
      "position": 0
    },
    {
      "token": "床前",
      "start_offset": 0,
      "end_offset": 2,
      "type": "CN_WORD",
      "position": 1
    },
    {
      "token": "明月光",
      "start_offset": 2,
      "end_offset": 5,
      "type": "CN_WORD",
      "position": 2
    },
    {
      "token": "明月",
      "start_offset": 2,
      "end_offset": 4,
      "type": "CN_WORD",
      "position": 3
    },
    {
      "token": "明",
      "start_offset": 2,
      "end_offset": 3,
      "type": "CN_WORD",
      "position": 4
    },
    {
      "token": "月光",
      "start_offset": 3,
      "end_offset": 5,
      "type": "CN_WORD",
      "position": 5
    },
    {
      "token": "月",
      "start_offset": 3,
      "end_offset": 4,
      "type": "CN_WORD",
      "position": 6
    },
    {
      "token": "光",
      "start_offset": 4,
      "end_offset": 5,
      "type": "CN_CHAR",
      "position": 7
    }
  ]
}
4、使用拼音分析器
GET /tystock/_analyze?
{
  "analyzer": "pinyin",
  "text" : "床前明月光"
}
{
  "tokens": [
    {
      "token": "chuang",
      "start_offset": 0,
      "end_offset": 1,
      "type": "word",
      "position": 0
    },
    {
      "token": "cqmyg",
      "start_offset": 0,
      "end_offset": 5,
      "type": "word",
      "position": 0
    },
    {
      "token": "qian",
      "start_offset": 1,
      "end_offset": 2,
      "type": "word",
      "position": 1
    },
    {
      "token": "ming",
      "start_offset": 2,
      "end_offset": 3,
      "type": "word",
      "position": 2
    },
    {
      "token": "yue",
      "start_offset": 3,
      "end_offset": 4,
      "type": "word",
      "position": 3
    },
    {
      "token": "guang",
      "start_offset": 4,
      "end_offset": 5,
      "type": "word",
      "position": 4
    }
  ]
}
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值