问题描述
在ES中,仅 match和bool必须匹配查询有什么区别?
What is the difference between Only match and bool must match query in ES?
首先,仅使用匹配查询
{
"query":{
"match":{
"address":"mill"
}
}
}
第二,使用复合查询
{
"query": {
"bool": {
"must": [
{ "match": { "address": "mill" } }
]
}
}
}
你能告诉我一切吗?
它们之间有什么区别?
Can you tell me everything?What is difference between them?
推荐答案
仅使用一次匹配项$
布尔必须
子句中的c $ c>则没有区别,当您要组合多个(布尔)条件时,布尔子句很有用,有关。它支持以下条件。
When you use only one match
inside a bool must
clause then there is no difference, the bool clause is useful when you want to combine multiple(boolean) criteria, more info on official ES doc. It supports below criteria.
- 必须
- 必须不
- 过滤器
- 应该
- must
- must_not
- filter
- should
让我以您的问题中的一个小例子为例。
Let me show by taking a small example from your question.
{
"mappings": {
"properties": {
"address": {
"type": "text"
},
"first_name" :{
"type" : "text"
}
}
}
}
索引3文档,都具有相同的地址工厂
,但具有不同的 first_name
Index 3 docs, all having same address mill
, but different first_name
{
"address" : "mill",
"first_name" : "Johnson"
}
{
"address" : "mill",
"first_name" : "Parker"
}
{
"address" : "mill",
"first_name" : "opster"
}
搜索查询以显示所有工厂
的地址,但必须不包含名字为 parker
Search query to show all adresses of mill
but must_not contain first_name as parker
{
"query": {
"bool": {
"must": [
{
"match": {
"address": "mill"
}
},
{
"must_not": {
"first_name": "parker"
}
}
]
}
}
}
仅结果2个地址
Result only 2 address
"hits": [
{
"_index": "so-60620921-bool",
"_type": "_doc",
"_id": "2",
"_score": 0.13353139,
"_source": {
"address": "mill",
"first_name": "opster"
}
},
{
"_index": "so-60620921-bool",
"_type": "_doc",
"_id": "3",
"_score": 0.13353139,
"_source": {
"address": "mill",
"first_name": "Johnson"
}
}
]
基于OP注释,提供,以详细了解性能方面。
Based on the OP comments, providing the query and filter context, to understand the performance aspects in details.
这篇关于在Elasticsearch中match和bool必须匹配查询有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!