一起来玩Elasticsearch,加我微信:wx1250134974
Elasticsearch认证复习准备
https://www.elastic.co/guide/cn/elasticsearch/guide/current/getting-started.html
##验证查询(explain 查询)
GET megacorp/_validate/query?explain
{
"query": {
"match" : {
"tweet" : "really powerful"
}
}
}
##查询
GET /website/blog/_search
{
"query": {
"match": {
"title": "second"
}
}
}
##组合查询
GET /website/blog/_search
{
"query": {
"bool": {
"must": {
"match": {
"title": "second"
}
},
"must_not": {
"match": {
"name": "mary"
}
},
"should": {
"match": {
"title": "full text"
}
},
"filter": {
"range": {
"age": {
"gt": 30
}
}
}
}
}
}
##term查询、terms(精确查询)
GET /website/blog/_search
{
"query": {
"term": {
"age": 10
}
}
}
GET /website/blog/_search
{
"query": {
"terms": {"age": [ 10,100 ]}
}
}
##exists、missing查询(类似于sql中的字段值为NULL或者IS not NULL)
GET /website/blog/_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "age"
}
}
}
}
}
GET /website/blog/_search
{
"query": {
"exists": {
"field": "title"
}
}
}
##排序
GET /megacorp/employee/_search
{
"query": {
"bool": {
"filter": {
"term": {
"about": "rock"
}
}
}
},
"sort": {
"age": {
"order": "desc"
}
}
}
##多字段排序(多级排序)
GET /megacorp/employee/_search
{
"query": {
"match": {
"about": "rock"
}
},
"sort": [
{
"_score": {
"order": "desc"
}
},
{
"age": {
"order": "asc"
}
}
]
}
一起来玩Elasticsearch,加我微信:wx1250134974