【发布时间】:2017-04-27 20:20:18
【问题描述】:
我对 ES 很陌生,
我正在使用 ingest-attachments-processor-plugin 和 elasticsearch 索引 pdf 书籍,以将我的查询结果作为 PER hit 而不是结果 PER 文档返回。例如,如果我正在索引几本 pdf 书籍,我想大致返回每个匹配发生的段落,这样如果 1 个文档中有 3 个匹配项,则应该有 3 个结果(段落),如果另一个匹配项有 2 个匹配项文件,应该有 5 次点击。我们的目标是创建一个可以从这些书中检索正确答案的工具。
1) 这可以通过弹性搜索实现吗? Solr 能解决这个问题吗? 2)我如何让它返回说一段,我不相信ES理解句子结构吗?有这个插件吗? 3) 我是否应该按段落解析文档(就像 Watson 使用 Document Conversion API 处理答案单元一样)然后索引到 ES 中?
这是我目前在 python 中使用的查询:
def execute_es_query(query_input, index, doc_type):
body_query = {
"stored_fields": [],
"query": {
"query_string": {
"default_field": "attachment.content",
"query": query_input
}
},
"highlight": {
"pre_tags": "<span>",
"post_tags": "</span>",
"fields": {
"attachment.content":{}
}
}
}
response = es_client.search(index= index, doc_type = doc_type, body = body_query)
return response['hits']['hits']
def fetch_response(response):
num = 1
for i in response:
print "Result:", num
for j in i['highlight']['attachment.content']:
print j
print "\n"
num+=1
【问题讨论】:
-
你想让 ES 在结果中只返回段落字段,而不是整个文档吗?
-
是的,就像书中的段落作为每个结果而不是整个文档作为一个结果。
标签: python elasticsearch