2.ElasticSearch 高级查询语法Query DSL实战
warning:
这篇文章距离上次修改已过180天,其中的内容可能已经有所变动。
GET /_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "Elasticsearch"
}
}
],
"filter": [
{
"range": {
"publish_date": {
"gte": "2015-01-01",
"lte": "2016-12-31"
}
}
}
],
"should": [
{
"match": {
"content": "Elasticsearch"
}
}
],
"must_not": [
{
"match": {
"content": "apache"
}
}
]
}
}
}
这个查询使用了布尔查询(bool query),它结合了必须匹配(must)、过滤(filter)、应当匹配(should)和不能匹配(must\_not)的查询子句。这是一个更为复杂的查询示例,它演示了如何在title
字段中搜索"Elasticsearch",同时确保内容在指定的日期范围内,并且在content
字段中可以找到"Elasticsearch"。同时,它还排除了在content
字段中含有"apache"的文档。这个查询展示了如何在Elasticsearch中构建更为复杂的查询逻辑。
评论已关闭