繁体   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