我需要从elasticseatch数据库中获取分析后的文本。我知道我可以使用analyze API将分析器应用于任何文本,但是,由于文本已经在索引过程中进行了分析,因此应该有一种方法来访问分析的数据。
以下是我要使用analyze API和Python Elasticsearch执行的操作
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)我注意到这个过程实际上相当慢。因此,直接从索引数据中获取数据应该要快得多。
发布于 2018-02-12 18:31:20
使用termvectors api应该可以完成这项工作,但是您必须指定每个条目的id,并且必须启用它(因为信息是存储的)。如果你不想这样,那么你已经在使用正确的方法了。
示例如下:
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
https://stackoverflow.com/questions/48716194
复制相似问题