elasticsearch篇:DSL查询语法
Elasticsearch的查询语言(Query DSL)是一种JSON形式的语法,用于构建查询。以下是一些基本查询的例子:
- 全文搜索查询(Full text search):
GET /_search
{
"query": {
"match": {
"message": "elasticsearch"
}
}
}
- 多字段匹配查询(Multi-field match query):
GET /_search
{
"query": {
"multi_match": {
"query": "elasticsearch",
"fields": ["title^2", "*_name"]
}
}
}
- 范围查询(Range query):
GET /_search
{
"query": {
"range": {
"age": {
"gte": 20,
"lt": 30
}
}
}
}
- 过滤器查询(Filter query):
GET /_search
{
"query": {
"bool": {
"must": {
"match": {
"message": "elasticsearch"
}
},
"filter": {
"range": {
"timestamp": {
"gte": "2014-01-01",
"lt": "2015-01-01"
}
}
}
}
}
}
- 精确匹配查询(Term query):
GET /_search
{
"query": {
"term": {
"category": "electronics"
}
}
}
- 布尔查询(Boolean query):
GET /_search
{
"query": {
"bool": {
"must": { "match": { "title": "elasticsearch" }},
"must_not": { "match": { "title": "kibana" }},
"filter": { "range": { "price": { "lte": 100 }}}
}
}
}
- 地理坐标查询(Geo-distance query):
GET /_search
{
"query": {
"geo_distance": {
"distance": "20km",
"pin.location": {
"lat": 40,
"lon": -70
}
}
}
}
- 高亮查询(Highlight query):
GET /_search
{
"query": {
"match": {
"message": "elasticsearch"
}
},
"highlight": {
"fields": {
"message": {}
}
}
}
这些查询可以根据需求进行组合和嵌套,以构建更复杂的搜索逻辑。
评论已关闭