多个搜索条件 & 短语匹配 (同时包含"广州"和"东") {
"bool" : {
"must":[],
"should":[],
"must_not":[],
}
} | DSL: {
"query": {
"bool": {
"must": [
[
{ "match_phrase": { "golf_course_name": "广州 " } },
{ "match": { "language_type": "1" } },
{ "range": { "id": { "gte": "11260870" } } }
]
]
}
}
} |
复杂搜索外层 OR 内部 AND: SELECT document FROM prices
WHERE golf_course_name = "广州"
OR ( golf_course_name = "东" AND price = 30 ) | {
"query": {
"bool": {
"should": [
{
"match": { "golf_course_name": "广州" }
},
{
"bool": {
"must": [
{ "term": { "golf_course_name": "东" } },
{ "term": { "price": 30 } }
]
}
}
]
}
}
} |
OR & 条件 & 范围搜索 | DSL: {
"query": {
"bool": {
"should": [
[
{ "range": { "bdate": { "gte": "1529337600" } } },
{ "match": { "language_type": "1" } }
],
[
{ "match": { "language_type": "2" } }
]
]
}
}
} |
过滤器(filter) 高效执行结构化搜索 exists排除空值 | DSL: {
"query": {
"bool": {
"must": [
[
{ "match": { "golf_course_name": "东" } }
]
],
"filter": [
{
"range": { "id": { "gte": "11193704" } }
},
{
"exists": { "field": "golf_course_name" }
}
]
}
}
} |
多重元素的时候需要把它转数组 [range] malformed query, expected [END_OBJECT] but found [FIELD_NAME] | |
过滤顺序 | 在 bool 条件中过滤器的顺序对性能有很大的影响。 更详细的过滤条件应该被放置在其他过滤器之前,以便在更早的排除更多的文档。 假如条件 A 匹配 1000 万个文档,而 B 只匹配 100 个文档,那么需要将 B 放在 A 前面。 |
| match 查询可以以一种低级别term 查询的方式执行。 |
| 提高精度搜索:minimum_should_match {
"query": {
"match": {
"golf_course_name": {
"query": "广 东",
"operator": "and",
"minimum_should_match": "75%"
}
}
}
} 控制多少should 子句需要被匹配:minimum_should_match {
"query": {
"bool": {
"should": [
{ "match": { "title": "brown" }},
{ "match": { "title": "fox" }},
{ "match": { "title": "dog" }}
],
"minimum_should_match": 2 <1>
}
}
} |
| |
转载于:https://my.oschina.net/u/3359005/blog/1914931