重新啓用分配路由
PUT /_cluster/settings
{
"transient" : {
"cluster.routing.allocation.enable" : "all"
}
}
查詢所有索引
GET _cat/indices?v
查詢目標索引
GET 索引名/_search
查詢 某個type的信息
GET 索引名/type名/_search
# 建立表結構
# index 設置爲false表示不建立索引,interger和keyword表示精確查找
PUT qinqin
{
"mappings": {
"doc": {
"properties": {
"address": {
"type": "text",
"analyzer": "ik_max_word"
},
"age": {
"type": "integer"
},
"shengFenZheng": {
"type": "keyword"
},
"like": {
"type": "text",
"index": false
}
}
}
}
}
GET qinqin/_mapping
PUT qinqin/doc/1
{
"address": "潢川 付店",
"age": 35,
"shengFenZheng": "鄭州洛陽",
"like": "看書 看電影"
}
PUT qinqin/doc/2
{
"address": "潢川 紅莊",
"age": 35,
"shengFenZheng": "鄭州開封",
"like": "看書寫字"
}
PUT qinqin/doc/3
{
"address": "潢川 馬莊",
"age": 36,
"shengFenZheng": "滎陽開封",
"like": "看書象棋 "
}
PUT qinqin/doc/4
{
"address": "光山馬莊",
"age": 37,
"shengFenZheng": "平頂山開封",
"like": "聽歌象棋 "
}
# 查詢id爲1的文檔
GET qinqin/doc/1
# 查詢所有
GET qinqin/doc/_search
{
"query":{
"match_all":{}
}
}
# 分頁
GET qinqin/doc/_search
{
"from":0,
"size":100,
"query":{
"term":{
"age": 3
}
}
}
# 按關鍵字降序排列
GET qinqin/doc/_search
{
"from":0,
"size":100,
"query":{
"match_all":{}
},
"sort":[
{"age":{"order":"desc"}}
]
}
# integer 精確匹配
GET qinqin/_search
{
"query":{
"match": {
"age": 35
}
}
}
# keyword 精確匹配
GET qinqin/_search
{
"query":{
"match": {
"shengFenZheng": "鄭州開封"
}
}
}
# index=false 表示不建立索引
GET qinqin/_search
{
"query":{
"match": {
"like": "聽歌象棋"
}
}
}
# 全文檢索
GET qinqin/_search
{
"query":{
"match": {
"address": "潢川張莊"
}
}
}
# gt:大於,gte:大於等於,lt:小於,lte:小於等於
# 查詢 35<=age<=36 所有文檔
GET qinqin/_search
{
"query":{
"range": {
"age": {
"gte": 35,
"lte": 36
}
}
}
}
# 字段平均計算
GET qinqin/_search
{
"aggs": {
"avg_age": {
"avg": {
"field": "age"
}
}
}
}
# 字段分組聚合,統計總和
GET qinqin/_search
{
"aggs": {
"avg_age": {
"terms": {
"field": "age"
}
},
"sum_age": {
"sum": {
"field": "age"
}
}
}
}
# 查某個字段的最小值最大值
GET qinqin/_search
{
"aggs": {
"min_age": {
"min": {
"field": "age"
}
},
"max_age": {
"max": {
"field": "age"
}
}
}
}
# 過濾查詢,查詢年齡大於等於35
GET qinqin/_search
{
"aggs":{
"recent_sales": {
"filter": {
"range": {
"age": {
"from": 35
}
}
}
}
}
}
# 統計某個字段去重後的數量
GET /qinqin/doc/_search
{
"size": 0,
"aggs": {
"distinct_ages": {
"cardinality": {
"field": "age"
}
}
}
}
# 數據直方圖
GET /qinqin/doc/_search
{
"size": 0,
"aggs": {
"ages": {
"date_histogram": {
"field": "age",
"interval":2
}
}
}
}