我是 Elasticsearch 和 Python 的初學(xué)者,我在 Elasticsearch 中使用一些數(shù)據(jù)創(chuàng)建了一個索引,我想使用 python 對這些數(shù)據(jù)執(zhí)行查詢請求。這是我在 Kibana 開發(fā)工具中創(chuàng)建的數(shù)據(jù)映射:PUT /main-news-test-data{ "mappings": { "properties": { "content": { "type": "text" }, "title": { "type": "text" }, "lead": { "type": "text" }, "agency": { "type": "keyword" }, "date_created": { "type": "date" }, "url": { "type": "keyword" }, "image": { "type": "keyword" }, "category": { "type": "keyword" }, "id":{ "type": "keyword" } } }}這是我的 Python 代碼,其中我們給它一個關(guān)鍵字和一個類別號,它必須檢查彈性數(shù)據(jù)的標(biāo)題、引導(dǎo)和內(nèi)容字段中是否有匹配的關(guān)鍵字,并檢查輸入的類別號和數(shù)據(jù)類別號并返回/打印出符合此條件的任何對象:from elasticsearch import Elasticsearchimport json,requestses = Elasticsearch(HOST="http://localhost", PORT=9200)es = Elasticsearch()def QueryMaker (keyword,category): response = es.search(index="main-news-test-data",body={"from":0,"size":5,"query":{"multi_match":{ "content":keyword,"category":category,"title":keyword,"lead":keyword}}}) return(response)if __name__ == '__main__': keyword = input('Enter Keyword: ') category = input('Enter Category: ') #startDate = input('Enter StartDate: ') #endDate = input('Enter EndDate: ') data = QueryMaker(keyword,category) print(data)但是當(dāng)我將數(shù)據(jù)提供給輸入時,我收到此錯誤:elasticsearch.exceptions.RequestError: RequestError(400, 'parsing_exception', '[multi_match] query does not support [content]')我究竟做錯了什么?編輯:關(guān)鍵字必須包含在標(biāo)題、線索和內(nèi)容中,但不必與它們相同
1 回答

暮色呼如
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個贊
您的multi_match查詢語法在這里是錯誤的,我也認(rèn)為您需要這樣的東西,
{
? "from":0,
? "size":5,
? "query": {
? ? "bool": {
? ? ? "should": [
? ? ? ? {
? ? ? ? ? "multi_match" : {
? ? ? ? ? ? "query":? ? ? keyword,
? ? ? ? ? ? "fields":? ? ?[ "content", "title","lead" ]
? ? ? ? ? }
? ? ? ? },
? ? ? ? {
? ? ? ? ? "multi_match" : {
? ? ? ? ? ? "query":? ? ? category,
? ? ? ? ? ? "fields":? ? ?[ "category" ]
? ? ? ? ? }
? ? ? ? }
? ? ? ]
? ? }
? }
}
添加回答
舉報(bào)
0/150
提交
取消