使用API分析文本
当跟踪信息如何在Elasticsearch索引中存储的时候,使用分析API来测试分析的过程是十分有用的。这个API允许你向Elasticsearch发送任何文本,指定所使用的分析器、分词器或者分词过滤器,然后获取分析后的分词。
全局分析器
POST /_analyze
{
"analyzer":"ik_smart",
"text":"这是title4"
}
{
"tokens" : [
{
"token" : "这是",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "title4",
"start_offset" : 2,
"end_offset" : 8,
"type" : "LETTER",
"position" : 1
}
]
}
索引中的分析器
POST /get-together/_analyze
{
"analyzer": "myCustomAnalyzer",
"text":"share your experience with NoSql"
}
自己组合分析器
POST /_analyze
{
"char_filter": ["html_strip"],
"tokenizer": "whitespace",
"filter": ["lowercase"],
"text": "SHARE <b>your</b> experience with NoSql"
}
基于某个字段映射的分析
# users的bobby是ik_max_word
POST /users/_analyze
{
"field": "hobby",
"text": "哈喽,大家好"
}