簡體   English   中英

彈性搜索查詢

[英]Elastic search querying

我的彈性搜索查詢遇到一些問題。 我有以下字段,Patientid,Patientfirstname,Patientmidname和Patientlastname。 我希望能夠在這4個字段之一中輸入並獲得匹配的結果。 到目前為止,僅當我使用Patientid時,查詢才有效。 如果我鍵入“哈利”(名字)或中間名/姓氏之類的信息,則不會查詢它。 單個詞條查詢適用於每個詞條。

q = Q({"bool": { "should": [ {"term":{"patientid":text}}, {"wildcard":{"patientlastname":"*"+text+"*"}}, {"wildcard":{"patientfirstname":"*"+text+"*"}}, {"wildcard":{"patientmidname":"*"+text+"*"}} ]}})

r = Search().query(q)[0:10000]

匹配取決於您的分析儀,我建議僅使用:

Search().query('multi_match', query=text, fields=['patientid', 'patientlastname', 'patientfirstname', 'patientmidname'])

它將跨這些字段查詢(您可以在[0]中了解有關multi_match查詢的不同type )。

您只需要確保正確分析了所有患者姓名字段即可(有關詳細信息,請參見[1])。

0- https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/query-dsl-multi-match-query.html 1- https://www.elastic.co/guide/zh-CN/elasticsearch /reference/6.4/analysis.html#_index_time_analysis

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM