赞
踩
1. 创建索引。
创建book索引
put 192.168.0.132:9200/book
{
"settings":{
"number_of_shards":3,
"number_of_replicas": 1
},
"mappings":{
"novel":{
"properties":{
"title":{
"type":"text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"store": false
},
"word_count":{
"type":"integer"
},
"author":{
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"store": false
},
"publish_date":{
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd||epoch_millis"
}
}
},
"literature":{
}
}
}
number_of_shards 是分片数,
number_of_replicas是备份数。
novel 和 literature 是类型
删除book索引
DELETE 192.168.0.131:9200/book
2.插入数据
post 192.168.0.131:9200/book/novel
{
"author":"欧阳花瓶",
"title": "China",
"word_count":31,
"date":"1994-09-01"
}i
3 .修改索引数据
192.168.0.131:9200/book/novel/6/_update
{
"doc":{
"author": "赵六5"
}
}
192.168.0.131:9200/索引/类型/id/_update
4.删除索引数据
DELTE 192 .168.0.131:9200/book/novel/6
5. 查询
根据ID查询索引
get 192.168.0.131:9200 /索引/类型/id
查询所有数据
GET 192.168.0.131:9200/book/_search
查询数据分页
GET 192.168.0.131:9200/book/_search
{
"query":{
"match_all":{}
},
"from":0,
"size": 10
}
match 查询
GET 192.168.0.131:9200/book/_search
{
"query":{
"match":{
"author": "张三"
}
}
}
排序
GET 192.168.0.131:9200/book/_search
{
"query":{
"match":{
"author": "张三"
}
},"sort":[
{"date":{"order":"desc"}}
]
}
聚合查询
GET 192.168.0.131:9200/book/_search
{
"aggs":{
"group_by_word_count": {
"terms":{ "field":"word_count" }
}
}
}
GET 192.168.0.131:9200/book/_search
{
"aggs":{
"group_by_word_count": {
"stats":{ "field":"word_count" }
}
}
}
短语匹配(Phrase Matching)
GET 192.168.0.131:9200/book/_search
{
"query":{
"match_phrase":{
"author": "玛丽"
}
}
}
multi_match 查询
GET 192.168.0.131:9200/book/_search
{
"query":{
"multi_match":{
"query":"玛丽",
"fields":["author","title"]
}
}
}
query_string 查询
GET 192.168.0.131:9200/book/_search
{
"query":{
"query_string":{
"query":"西游记 or 水浒传"
}
}
}
GET 192.168.0.131:9200/book/_search
{
"query":{
"query_string":{
"query":"玛丽 or 水浒传" ,
"fields":["author","title"]
}
}
}
term 查询
GET 192.168.0.131:9200/book/_search
{
"query":{
"term":{
"title":"水浒传"
}
}
}
range 查询
GET 192.168.0.131:9200/book/_search
{
"query":{
"range":{
"date":{
"gte":"1994-09-01"
}
}
}
}
query filter 查询
GET 192.168.0.131:9200/book/_search
{
"query":{
"bool":{
"filter":{
"term":{"word_count":51}
}
}
}
}
固定分数查询
GET 192.168.0.131:9200/book/_search
{
"query":{
"constant_score":{
"filter":{
"match":{
"title":"西游记"
}
}
}
}
}
bool查询
should
GET 192.168.0.131:9200/book/_search
{
"query":{
"bool":{
"should":[{
"match":{
"title":"西游记"
}
},
{
"match":{
"author": "超级玛丽"
}
}
]
}
}
}
must
GET 192.168.0.131:9200/book/_search
{
"query":{
"bool":{
"must":[{
"match":{
"title":"西游记"
}
},
{
"match":{
"author": "超级玛丽"
}
}
]
}
}
}
must_not
GET 192.168.0.131:9200/book/_search
{
"query":{
"bool":{
"must_not":{
"match":{
"title": "西游记"
}
}
}
}
}
嵌套查询
{
"settings":{
"number_of_shards":3,
"number_of_replicas": 1
},
"mappings": {
"earthblog": {
"properties": {
"orderId": {
"type": "keyword"
},
"totalAmount": {
"type": "long"
},
"discountAmount":{
"type": "long"
},
"status":{
"type": "integer"
},
"createTime":{
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd||epoch_millis"
},
"orderDetails": {
"type": "nested",
"properties": {
"productId": {
"type": "long"
},
"productName": {
"analyzer": "ik_max_word",
"type": "text"
},
"productType": {
"type": "short"
},
"status": {
"type": "short"
},
"createTime":{
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd||epoch_millis"
}
}
}
}
}
}
}
嵌套查询
192.168.0.132:9200/order/order/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "orderDetails",
"query": {
"bool": {
"must": [{
"match": {
"orderDetails.productName": "AOC显示器"
}
},
{
"match": {
"orderDetails.productType": 1
}
}
]
}
}
}
}
]
}
}
}
二、Kibana基本操作
1、点击这个小扳手是命令界面
创建索引
put index_icoding (创建一个index_icoding的索引)
查看索引信息,get index_icoding
删除索引
delete index_icoding
关闭索引
post index_icoding/_close
打开索引
post index_icoding/_open
操作映射
添加映射
put index_icoding/_mapping/class
{
"properties":{
"name":{
"type": "text"
},
"grade":{
"type": "integer"
}
}
}
查询映射
添加字段
put index_icoding/_mapping/class
{
"properties":{
"address":{
"type": "text"
}
}
}
操作文档
插入文档
post index_icoding/class
{
"name":"docter",
"grade":19
}
查询文档
get /index_icoding/class/_search
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。