第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python中Elasticsearch多字段查詢請求

Python中Elasticsearch多字段查詢請求

繁星coding 2023-09-12 20:10:53
我是 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" ]

? ? ? ? ? }

? ? ? ? }

? ? ? ]

? ? }

? }

}


查看完整回答
反對 回復(fù) 2023-09-12
  • 1 回答
  • 0 關(guān)注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號