簡介
ELK是三個開源軟件的縮寫,分別表示:Elasticsearch、Logstash和Kibana,這裏主要講述kibana的基本操作命令;
實踐
1.9200訪問索引庫
2.9100訪問非官方管理工具
3.5601訪問kibana管理工具
//刪除庫
DELETE testindex
//新建庫
PUT testindex
//新建表
PUT testindex/testtype/_mapping
{
"properties":{}
}
//新建表和表結構
PUT testindex/testtype/_mapping
{
"properties": {
"@timestamp": {
"type": "date",
"index": false //表示該字段不能被搜索到
},
"@version": {
"type": "text",
"index": false
},
"address": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"analyzer": "ik_max_word", //該字段建立分詞
"search_analyzer": "ik_max_word" //將該字段添加到分詞,表示該字段能被搜索到
},
"area_code": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
//新增表字段
PUT testindex/testtype/_mapping
{
"properties": {
"newfield":{
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"analyzer": "ik_max_word",//指定分詞解析器
"search_analyzer": "ik_max_word"
}
}
}
//刪除所有數據
POST testindex/testtype/_delete_by_query
{
"query": {
"match_all": {}
}
}
//搜索全部,降序排列
GET testindex/testtype/_search
{
"sort":[
{
"inputtime":{
"order":"desc"
}
}
]
}
//查看錶結構
GET testindex/testtype/_mapping
//查詢index的所有_mapping
GET testindex/_mapping
//查詢表數據
GET testindex/testtype/_search
{
"query": {}
}
//分頁查詢
GET supplier/user/_search
{
"query": { "match_all": {} },
"from": 1,
"size": 1
}
//模糊查詢
GET testindex/testtype/_search
{
"query": {
"match": {
"name": "莉" //name是字段,後面的模糊的字
}
}
}
//模糊查詢指定多字段
GET testindex/testtype/_search
{
"query": {
"multi_match": {
"query": "莉", //需要模糊查詢的關鍵字
"fileds":["name","content"] //需要查詢匹配的字段
}
}
}
//模糊查詢,添加高亮
GET testindex/testtype/_search
{
"query": {
"match": {
"name": "莉" //name是字段,後面的模糊的字
},
"highlight": { //高亮指令
"fields": { //指定字段
"name":{} //該字段和上面的數量和名稱需要一致
}
}
}
}
//模糊查詢指定多字段,添加高亮
GET testindex/testtype/_search
{
"query": {
"multi_match": {
"query": "莉", //需要模糊查詢的關鍵字
"fileds":["name","content"] //需要查詢匹配的字段
},
"highlight": { //高亮指令
"fields": { //指定字段
"name":{} //該字段和上面的數量和名稱需要一致
"ocntent":{}
}
}
}
}
//範圍查詢
GET testindex/testtype/_search
{
"query": {
"range": { //範圍指令
"createtime": { //時間字段
"gte":"2017-01-01", //最小值
"lte":"2017-002-02" //最大值
}
}
}
}
//精確查詢term(該term表示的是精確分詞,但該字段必須在創建的時候標識成不分詞,然後才能精確查詢)
GET testindex/testtype/_search
{
"query": {
"term": {
"name":"六月"
}
}
}
//精確查詢terms(一個字段,包含指定的多個關鍵詞,即可查詢出來)
GET testindex/testtype/_search
{
"query": {
"terms": {
"name":["六","月"]
}
}
}
//修改索引字段內容(根據document的id修改),必須是全量替換,不替換的內容也需要添加上去
PUT testindex/testtype/AV9Lp12vBX5F2aXqts8- //最後一個爲documentid具備唯一性
{
"name":"六月"
}
//刪除一個document行,包括很多個字段
DELETE testindex/testtype/AV9Lp12vBX5F2aXqts8- //最後一個爲documentid,具備唯一性
//測試一個字符串的分詞
GET /_analyze
{
"analyzer": "standard",
"text": ["六月"]
}
總結
實踐是檢驗認識真理性的唯一標準,自己動手,豐衣足食~~