您的位置:首页 > 大数据 > 人工智能

Elasticsearch _analyze, _explain和 _search_shards工具

2015-11-06 10:52 525 查看
_analyze, _explain和_search_shards是Elasticsearch提供的3个辅助API,经常不为人所知和所用。_explain 用来帮助分析文档的relevance
score是如何计算出来的;_search_shards则是用来分析某个搜索请求将会访问到哪些节点以及shard,这在性能调优的时候还是很有用的;而_analyze是Elasticsearch一个非常有用的API,它可以帮助你分析每一个field或者某个analyzer/tokenizer是如何分析和索引一段文字的。

例如, 下面例子用test索引默认analyzer来分析 "this is a test"

GET /test/_analyze?text="this is a test"

执行结果:

{

"tokens": [

{

"token": "this",

"start_offset": 1,

"end_offset": 5,

"type": "<ALPHANUM>",

"position": 1

},

{

"token": "is",

"start_offset": 6,

"end_offset": 8,

"type": "<ALPHANUM>",

"position": 2

},

{

"token": "a",

"start_offset": 9,

"end_offset": 10,

"type": "<ALPHANUM>",

"position": 3

},

{

"token": "test",

"start_offset": 11,

"end_offset": 15,

"type": "<ALPHANUM>",

"position": 4

}

]

}

你也可以用制定的analyzer来分析,例如:

GET /test/_analyze?analyzer=whitespace&text=this is a test

此外, 你还可以使用指定field的analyzer来分析,例如:

GET/test/_analyze?field=typename.fieldname&text=this is a test

除了上述的API之外, _cat系列API也是常用的系统诊断工具,和curl结合在一起效果就更好了, 参见
Introducing : The cat API.



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: