es crul查询(一)

时间:2021-04-25 07:56:24
C:\Users\Administrator>elasticdump --input=D:\test --output=http://localhost:9200/logs_apipki_20190102
#查询所有索引信息
http://localhost:9200/_cat/indices?v
#轻量级搜索
curl -X GET "localhost:9200/test/user/_search?q=last_name:Smith" #表达式搜索
curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"match" : {
"last_name" : "Smith"
}
}
}
'
#filter实现结勾化查询
curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"bool": {
"must": {
"match" : {
"last_name" : "smith"
}
},
"filter": {
"range" : {
"age" : { "gt" : 30 }
}
}
}
}
}
'
#模糊匹配(向下匹配,并根据匹配的分数排序)
curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"match" : {
"about" : "rock climbing"
}
}
}
'
#短语搜索(精准匹配)
curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"match_phrase" : {
"about" : "rock climbing"
}
}
}
'
#高亮查询
curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
"query" : {
"match_phrase" : {
"about" : "rock climbing"
}
},
"highlight": {
"fields" : {
"about" : {}
}
}
}
'
#聚合函数(类似group by)
curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
"aggs": {
"all_interests": {
"terms": { "field": "interests" }
}
}
}
'
#先根据query条件过滤,在聚合
curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
"query": {
"match": {
"last_name": "smith"
}
},
"aggs": {
"all_interests": {
"terms": {
"field": "interests"
}
"aggs" : {//分级聚合各个intrests对应的平均年龄
"avg_age" : {
"avg" : { "field" : "age" }
}
}
}
}
}
'