简介
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": ["六月"]
}
总结
实践是检验认识真理性的唯一标准,自己动手,丰衣足食~~