简体   繁体   English

弹性搜索查询

[英]Elastic search querying

I'm having some issues with my elastic search querying. 我的弹性搜索查询遇到一些问题。 I have the following fields, patientid, patientfirstname, patientmidname, and patientlastname. 我有以下字段,Patientid,Patientfirstname,Patientmidname和Patientlastname。 I want to be able to enter in either one of those 4 fields and get matching results returned. 我希望能够在这4个字段之一中输入并获得匹配的结果。 So far my query works only if I use a patientid. 到目前为止,仅当我使用Patientid时,查询才有效。 If i type something like harry (firstname) or middle/last name it doesn't query it. 如果我键入“哈利”(名字)或中间名/姓氏之类的信息,则不会查询它。 Individual term querying works for each of them. 单个词条查询适用于每个词条。

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

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

the matching depends on your analyzers, what I would recommend is to just use: 匹配取决于您的分析仪,我建议仅使用:

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

which will query across those fields (you can read about different type s of multi_match query in [0]). 它将跨这些字段查询(您可以在[0]中了解有关multi_match查询的不同type )。

You just need to make sure that all the patient name fields are properly analyzed (see [1] for details) 您只需要确保正确分析了所有患者姓名字段即可(有关详细信息,请参见[1])。

0 - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html 1 - https://www.elastic.co/guide/en/elasticsearch/reference/6.4/analysis.html#_index_time_analysis 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