1、計算總數
{ "size": 0, "aggs": { "count_nameCount": { "terms": { "field": "data.id" } } } }
2、查詢所有
GET /logstandard_data/logstandard_data/_search { "query": { "match_all": {} } }
3、查詢某個字段匹配
GET /logstandard_data/logstandard_data/_search { "query" : { "bool" : { "must" : [ {"match": {"data.bsm": 574599426}} ] } } }
4、查詢某個字段,按時間倒敘排序
GET /logstandard_data/logstandard_data/_search { "query": { "bool": { "must": [ { "match": { "data.interfaceCode": 1341 } } ] } }, "sort": [ { "data.requestTime.keyword": { "order": "desc" } } ] }
5、時間范圍查詢
GET /logstandard_data/logstandard_data/_search { "query": { "bool": { "must": [ { "match": { "data.interfaceCode": 1341 } }, { "match": { "resource.status": "0" } } ], "filter":[ {"range": { "data.requestTime": { "gte": 1594915200000, "lte": 1595001599000 } } } ] } }, "sort": [ { "data.requestTime.keyword": { "order": "desc" } } ] }
6、創建索引
PUT test
上面沒有設置分片,就默認主分片為5,副分片為1
設置分片闖將索引
PUT /test { "settings":{ "index":{ "number_of_shards":3, "number_of_replicas":1 } } }
number_of_shards是主分片的數量;number_of_replicas是副本分片的數量(這里提一下,number_of_replicas副本分片的數量是面向主分片的,所以這個值為1時代表每一個主分片有一個副本分片)
引用:https://www.cnblogs.com/progor/p/11548269.html#%E5%88%9B%E5%BB%BA%E7%B4%A2%E5%BC%95
7、設置索引數據中格式
POST /book/novel/_mappings { "novel":{ "properties": { "word_count": { "type": "integer" }, "author": { "type": "keyword" }, "title": { "type": "text" } } } }
book為索引名,novel為type類型
字段數據類型:請查看https://www.cnblogs.com/chy18883701161/p/12723658.html
設置日期的格式可以
PUT my_index { "mappings": { "_doc": { "properties": { "updated_date": { "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" } } } } }
設置對象中包含對象的類型
{ "properties": { "region": { "type": "keyword" }, "manager": { "properties": { "age": {"type": "short"}, "name": { "properties": { "first": {"type": "keyword"}, "last": {"type": "text"} } } } } } }
8、插入數據
POST indextest001/product { "title": "test title 001", "description": "this is a random desc ", "price": 22.6, "onSale": "true", "type": 2, "createDate": "2018-01-12" }