居然是你

大佬们有没试过在索引文档的时候连同分词结果一起存起来的?

Elasticsearch | 作者 God_lockin | 发布于2019年03月13日 | 阅读数:1595

我能想到的是用pipeline去设值,但是好像没有直接的接口可以把这个值取出来?
{
"content":"今天天气不错"
}
分词结果:
今天,天,天气,不错
最后存下来的文档为:
{
"content":"今天天气不错",
"words":"今天 天 天气 不错"
}
如果能对分词结果去重的话就更完美了
已邀请:

rochy - rochy_he

赞同来自:

为什么要存储分词结果呢?
如果想获取分词结果,调用 _analyze 接口即可

hapjin

赞同来自:

1,分词结果是可以存储的吧。参考一下 term_vector,docs-termvectors。你在定义索引的时候可以指定term_vector这个属性为yes,参考:mapping fields_term-vector
比如:
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"text": {
"type": "text",
"term_vector": "yes"
}
}
}
}
}

 然后,再通过就能拿到分词结果。
GET /my_index/_doc/1/_termvectors
{
"fields" : ["text"],
"offsets" : true,
"payloads" : true,
"positions" : true,
"term_statistics" : true,
"field_statistics" : true
}

我一般用这个来测试,生产环境不会开启它。
 
2,分词结果的去重,是与你配置的Analyzer分词器(Analyzer流程)有关的。
想看下某个字段 存储的 分词结果 还是可以的。。。。how-to-get-tokens-for-a-document
 
我自己测试了一下:
PUT了一篇文档:
PUT user/profile/1
{
  "nick":"人生 如梦"
}
 
Term情况:
{
"_index": "user",
"_type": "profile",
"_id": "1",
"_version": 1,
"found": true,
"took": 2,
"term_vectors": {
"nick": {
"field_statistics": {
"sum_doc_freq": 4,
"doc_count": 1,
"sum_ttf": 4
},
"terms": {
" ": {
"doc_freq": 1,
"ttf": 1,
"term_freq": 1
},
"人生": {
"doc_freq": 1,
"ttf": 1,
"term_freq": 1
},
"如": {
"doc_freq": 1,
"ttf": 1,
"term_freq": 1
},
"梦": {
"doc_freq": 1,
"ttf": 1,
"term_freq": 1
}
}
}
}
}

 

要回复问题请先登录注册