Joh*_*son 7 elasticsearch booleanquery elasticsearch-query
ES中Only match和bool必须匹配查询有什么区别?
首先,仅使用匹配查询
{
"query":{
"match":{
"address":"mill"
}
}
}
Run Code Online (Sandbox Code Playgroud)
二、使用复合查询
{
"query": {
"bool": {
"must": [
{ "match": { "address": "mill" } }
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我一切吗?他们之间有什么区别?
Ami*_*wal 10
match
当您在子句中仅使用一个bool must
时,没有区别,当您想要组合多个(布尔)条件时,bool 子句很有用,更多信息请参阅官方 ES 文档。它支持以下标准。
让我从你的问题中举一个小例子来说明。
{
"mappings": {
"properties": {
"address": {
"type": "text"
},
"first_name" :{
"type" : "text"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
mill
,但不同first_name
{
"address" : "mill",
"first_name" : "Johnson"
}
{
"address" : "mill",
"first_name" : "Parker"
}
{
"address" : "mill",
"first_name" : "opster"
}
Run Code Online (Sandbox Code Playgroud)
mill
但不得包含名字:parker
{
"query": {
"bool": {
"must": [
{
"match": {
"address": "mill"
}
},
{
"must_not": {
"first_name": "parker"
}
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
"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"
}
}
]
Run Code Online (Sandbox Code Playgroud)
基于OP注释,提供查询和过滤上下文,以详细了解性能方面。
归档时间: |
|
查看次数: |
9644 次 |
最近记录: |