gpt4 book ai didi

python - Elasticsearch-根据 'hit'返回结果,而不是文档

转载 作者:行者123 更新时间:2023-12-03 00:07:46 31 4
gpt4 key购买 nike

我对ES非常陌生,

我正在使用ingest-attachments-processor-plugin和elasticsearch为pdf图书编制索引,以PER命中而不是结果PER文档的形式返回查询结果。例如,如果我要为几本pdf图书编制索引,我想大致返回每次匹配发生的段落,这样,如果1个文档中有3个匹配项,则应该有3个结果(段落),而另一个文档中有2个匹配项文件也应该全部打5次。目的是创建一个从这些书中检索正确答案的工具。

1)elasticsearch有可能吗? Solr能够解决这个问题吗?
2)如何获得返回段落的信息,我不认为ES理解句子结构吗?是否有插件?
3)我是否应该按段落解析文档(就像Watson使用文档转换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

最佳答案

如果将段落存储为nestedchild文档,则可以使用inner-hits feature

来自文档:

{
"query" : {
"nested" : {
"path" : "attachment",
"query_string": {
"default_field": "attachment.content",
"query": query_input
}
"inner_hits" : {}
}
}
}

然后,响应将在每个返回的文档中包含一个名为 inner_hits的字段,其中包含每个返回的文档的匹配段落。

此方法仍将文档作为主要搜索结果返回。如果要搜索段落,我的建议是将它们编入索引作为单独的类型。

关于python - Elasticsearch-根据 'hit'返回结果,而不是文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43654232/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com