擅长:python、mysql、java
<p>在<code>match query</code>中,您已经将查询中的所有标记作为SQL中的OR查询进行搜索。在您的例子中,如果您有一个<code>multimatch query</code>字段,则表示您正在针对这3个字段中的任何一个搜索查询中的任何标记的匹配项-如果您没有将任何特定的映射分配给ES,则意味着您的文本字段已处理了一个<code>standard analyzer</code>请阅读<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html" rel="nofollow noreferrer">here</a>,该字段将字符串分隔为空格上的标记。因此,要添加一个要查询的新键,只需将一个新值连接到字符串<code>qs</code>:</p>
<pre><code>from document import DocClass
def globalsearch_elastic(request):
qs = request.GET.get('qs')
document = DocClass()
document_value = document.my_function() # you invoke a function in a class inside document.py that returns to you a string
page = request.GET.get('page')
if any([qs, document_value]):
queryable = " ".join([qs, document_value])
qs = PostDocument.search().query("multi_match", query=queryable, fields=["title", "content", "tag"])
qs = qs.to_queryset()
else:
return "No values to query"
</code></pre>