![](/img/trans.png)
[英]Using REST API JSON response as data to build reports in Python
[英]Pass JSON response of REST API as input data into APACHE SOLR
我有一個使用Flask構建的REST API。 它具有GET和POST方法。 該API返回JSON響應。 我希望SOLR使用REST API的URL來基於查詢對該響應執行搜索,並返回相關的搜索結果。
我該如何實現? SOLR是否僅將JSON 文件作為輸入,在這種情況下,我需要將端點的響應寫入JSON文件,將其放在示例文件夾中,然后傳遞給SOLR?
我希望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
這是部分正確的理解,但是您不必將其放在示例文件夾中。 您需要發布該JSON(或以Solr要求的格式格式化JSON),如上面提供的參考中所示。
希望這可以幫助。
謝謝阿米特! 在您共享的鏈接中,它具有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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.