[英]Elasticsearch with grouped query_string
{
"query":
{
"query_string" :
{
"query" : "((name:the_search_phrase) OR (keywords:the_search_phrase)) AND (city:Sydney, Australia)"
}
}
}
New to elasticsearch.弹性搜索的新手。 Building the JSON as per the documentation here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
根据此处的文档构建 JSON: https : //www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
The query runs, however, results with city other that Sydney, Australia
are returned too.但是,查询运行时,也会返回
Sydney, Australia
以外的其他城市的结果。 Why the AND part is not working?为什么 AND 部分不起作用?
I want the search phrase to match against either or both name, keywords but the city should be strictly Sydney.我希望搜索词组与名称、关键字中的一个或两个匹配,但城市应该严格为悉尼。
What you are doing is a full text query.您正在做的是全文查询。
city:Sydney, Australia
seems to be a filter query. city:Sydney, Australia
好像是过滤查询。 Like a WHERE clause in a SQL.就像 SQL 中的 WHERE 子句。 You are better off using a filter query for that.
您最好为此使用过滤器查询。
Look at the boolean query for examples,查看布尔查询以获取示例,
Something like this perhaps,大概是这样的,
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "the_search_term",
"fields": [
"name",
"keywords"
]
}
}
],
"filter": [
{
"match": {
"city": "Sydney, Australia"
}
}
]
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.