我有一个使用Flask构建的REST API。它具有GET和POST方法。该API返回JSON响应。我希望SOLR使用REST API的URL来基于查询对该响应执行搜索,并返回相关的搜索结果。
我该如何实现? SOLR是否仅将JSON 文件作为输入,在这种情况下,我需要将端点的响应写入JSON文件,将其放置在示例文件夹中,然后将其传递给SOLR?
答案 0 :(得分:0)
我希望SOLR使用REST API的URL根据查询对数据(JSON响应)执行搜索并返回相关的搜索结果
您将必须调用REST API,获取JSON响应并将其添加到Solr Index。然后,您可以使用Solr搜索该数据。
能否让我知道如何实现这一目标?有可能吗?
请查看此文档。它将帮助您索引JSON文档。 https://lucene.apache.org/solr/guide/7_1/uploading-data-with-index-handlers.html#solr-style-json
还是SOLR仅将JSON文件作为输入放置在示例文件夹中,在这种情况下,我需要将从RESTAPI接收到的响应写到json文件,将其放置在示例文件夹中,然后将其传递到SOLR < / p>
这是部分正确的理解,但是您不必将其放在示例文件夹中。您需要发布该JSON(或以Solr要求的格式格式化JSON),如上面提供的参考所示。
希望这会有所帮助。
答案 1 :(得分:0)
感谢阿米特!在您共享的链接中,它具有curl命令。但是我试图用Python做到这一点。我找到了解决方案!奇迹般有效。我还嵌入了一些评论以供进一步解释。
@app.route('/solrInput', methods = ['POST'])
def solr_input():
"""Get response data from MongoDB RESTAPI and feed into SOLR for indexing"""
#get mongoDB data from rest api
input_data = requests.get('http://127.0.0.1:5000/getAllRecords')
json_data = input_data.json()
#loop through response to fetch the values
for key, val in json_data.items():
payload = str(val)
response = requests.post("http://localhost:8983/solr/techs/update/json/docs?commit=true", data=payload)
if __name__ == "__main__":
app.run(debug=True)