Elasticsearch - 查看某个字段分词的效果
王猴卖瓜
共 7851字,需浏览 16分钟
·
2021-04-22 09:39
查看存入ES时的分词情况
查看分词代码
String text = "2020-10-21.17:31:18.843 BigManing.com java.lang.NullPointerException: null\n" +
"\tat com.dangdang.ddframe.job.executor.AbstractElasticJobExecutor.process$original$yfwDeDZA(AbstractElasticJobExecutor.java:206) [elastic-job-common-core-2.1.5.jar!/:?] Elasticsearch -查看某个字段分词的效果";
String indexName = "test";
AnalyzeRequest request = new AnalyzeRequest(indexName);
request.text(text);
request.field("msg");
// request.analyzer("standard");
AnalyzeResponse analyze = client.indices().analyze(request, RequestOptions.DEFAULT);
// 打印查看效果
System.out.println(JSON.toJSONString(analyze.getTokens(), true));
字段说明
filed
:对标test索引中哪个字段,默认使用相同的分词器text
:需要分词的内容也可以自定义 该字段使用哪个分词器
"standard"
分词结果
[
{
"attributes":{},
"endOffset":4,
"fragment":false,
"position":0,
"positionLength":1,
"startOffset":0,
"term":"2020",
"type":"<NUM>"
},
{
"attributes":{},
"endOffset":7,
"fragment":false,
"position":1,
"positionLength":1,
"startOffset":5,
"term":"10",
"type":"<NUM>"
},
{
"attributes":{},
"endOffset":13,
"fragment":false,
"position":2,
"positionLength":1,
"startOffset":8,
"term":"21.17",
"type":"<NUM>"
},
{
"attributes":{},
"endOffset":16,
"fragment":false,
"position":3,
"positionLength":1,
"startOffset":14,
"term":"31",
"type":"<NUM>"
},
{
"attributes":{},
"endOffset":23,
"fragment":false,
"position":4,
"positionLength":1,
"startOffset":17,
"term":"18.843",
"type":"<NUM>"
},
{
"attributes":{},
"endOffset":37,
"fragment":false,
"position":5,
"positionLength":1,
"startOffset":24,
"term":"bigmaning.com",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":68,
"fragment":false,
"position":6,
"positionLength":1,
"startOffset":38,
"term":"java.lang.nullpointerexception",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":74,
"fragment":false,
"position":7,
"positionLength":1,
"startOffset":70,
"term":"null",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":78,
"fragment":false,
"position":8,
"positionLength":1,
"startOffset":76,
"term":"at",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":147,
"fragment":false,
"position":9,
"positionLength":1,
"startOffset":79,
"term":"com.dangdang.ddframe.job.executor.abstractelasticjobexecutor.process",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":156,
"fragment":false,
"position":10,
"positionLength":1,
"startOffset":148,
"term":"original",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":165,
"fragment":false,
"position":11,
"positionLength":1,
"startOffset":157,
"term":"yfwdedza",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":197,
"fragment":false,
"position":12,
"positionLength":1,
"startOffset":166,
"term":"abstractelasticjobexecutor.java",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":201,
"fragment":false,
"position":13,
"positionLength":1,
"startOffset":198,
"term":"206",
"type":"<NUM>"
},
{
"attributes":{},
"endOffset":211,
"fragment":false,
"position":14,
"positionLength":1,
"startOffset":204,
"term":"elastic",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":215,
"fragment":false,
"position":15,
"positionLength":1,
"startOffset":212,
"term":"job",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":222,
"fragment":false,
"position":16,
"positionLength":1,
"startOffset":216,
"term":"common",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":227,
"fragment":false,
"position":17,
"positionLength":1,
"startOffset":223,
"term":"core",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":233,
"fragment":false,
"position":18,
"positionLength":1,
"startOffset":228,
"term":"2.1.5",
"type":"<NUM>"
},
{
"attributes":{},
"endOffset":237,
"fragment":false,
"position":19,
"positionLength":1,
"startOffset":234,
"term":"jar",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":257,
"fragment":false,
"position":20,
"positionLength":1,
"startOffset":244,
"term":"elasticsearch",
"type":"<ALPHANUM>"
},
{
"attributes":{},
"endOffset":260,
"fragment":false,
"position":21,
"positionLength":1,
"startOffset":259,
"term":"查",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":261,
"fragment":false,
"position":22,
"positionLength":1,
"startOffset":260,
"term":"看",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":262,
"fragment":false,
"position":23,
"positionLength":1,
"startOffset":261,
"term":"某",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":263,
"fragment":false,
"position":24,
"positionLength":1,
"startOffset":262,
"term":"个",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":264,
"fragment":false,
"position":25,
"positionLength":1,
"startOffset":263,
"term":"字",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":265,
"fragment":false,
"position":26,
"positionLength":1,
"startOffset":264,
"term":"段",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":266,
"fragment":false,
"position":27,
"positionLength":1,
"startOffset":265,
"term":"分",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":267,
"fragment":false,
"position":28,
"positionLength":1,
"startOffset":266,
"term":"词",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":268,
"fragment":false,
"position":29,
"positionLength":1,
"startOffset":267,
"term":"的",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":269,
"fragment":false,
"position":30,
"positionLength":1,
"startOffset":268,
"term":"效",
"type":"<IDEOGRAPHIC>"
},
{
"attributes":{},
"endOffset":270,
"fragment":false,
"position":31,
"positionLength":1,
"startOffset":269,
"term":"果",
"type":"<IDEOGRAPHIC>"
}
]
评论