首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从elasticsearch数据库中获取分析后的文本

如何从elasticsearch数据库中获取分析后的文本
EN

Stack Overflow用户
提问于 2018-02-10 09:03:30
回答 1查看 669关注 0票数 2

我需要从elasticseatch数据库中获取分析后的文本。我知道我可以使用analyze API将分析器应用于任何文本,但是,由于文本已经在索引过程中进行了分析,因此应该有一种方法来访问分析的数据。

以下是我要使用analyze API和Python Elasticsearch执行的操作

代码语言:javascript
复制
res = es.indices.analyze(index=app.config['ES_ARXIV_PAPER_INDEX'],
                         body={"char_filter": ["html_strip"],
                               "tokenizer" : "standard",
                                "filter" : ["lowercase", "stop", "snowball"],
                                "text" : text})
tokens = []
for token in res['tokens']:
    tokens.append(token['token'])
print("tokens = ", tokens)

我注意到这个过程实际上相当慢。因此,直接从索引数据中获取数据应该要快得多。

EN

回答 1

Stack Overflow用户

发布于 2018-02-12 18:31:20

使用termvectors api应该可以完成这项工作,但是您必须指定每个条目的id,并且必须启用它(因为信息是存储的)。如果你不想这样,那么你已经在使用正确的方法了。

示例如下:

代码语言:javascript
复制
PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "my_field": {
          "type": "text"
        }
      }
    }
  }
}

POST my_index/my_type/1
{
  "my_field": "this is a test"
}

GET /my_index/my_type/1/_termvectors?fields=*

https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/term-vector.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48716194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档