######### 查看原数据信息 ##########
# 查看集群的健康状态
GET _cat/health?v
# 查看集群的 index
GET _cat/indices?v
GET _cat/plugins?v
##### ik 分词测试 ###
GET _analyze
{
"analyzer": "ik_max_word"
, "text": ["学习近平平安归来"]
}
######### 数据的 PUT, POST, GET ###############
DELETE student
PUT student
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
},
"age": {
"type": "integer"
},
"sex": {
"type": "keyword"
},
"favo": {
"type": "text",
"analyzer": "ik_max_word"
}
}
}
}
# PUT 操作
PUT student/_doc/001
{
"name": "ylb",
"age": "99",
"sex": "男",
"favo": "学习近平"
}
PUT student/_doc/002
{
"name": "y002",
"age": "12",
"sex": "女",
"favo": "吃饭睡觉打豆豆..."
}
PUT student/_doc/003
{
"name": "y003",
"age": "13",
"sex": "女",
"favo": "学习旅游行走"
}
PUT student/_doc/004
{
"name": "y004",
"age": "13",
"sex": "男",
"favo": "学习旅行跑"
}
### GET 查看 student 中的数据
GET student/_search
# POST 操作
POST student/_doc
{
"name": "p004",
"age": "14",
"sex": "女",
"favo": "敲代码"
}
######### 检索 ############
# 全文档检索
GET student/_search
#
GET student/_search
{
"query": {
"bool": {
"filter": {
"term": {
"favo": "学习旅行"
}
}
}
}
}
# match: where ... or ...
GET student/_search
{
"query": {
"match": {
"favo": "学习旅行"
}
}
}
# match: where ... and ...
GET student/_search
{
"query": {
"match": {
"favo": {
"query": "学习旅行",
"operator": "and"
}
}
}
}
# 多条件匹配: filter ... must ...
GET student/_search
{
"query": {
"bool": {
"filter": {
"term": {
"sex": "男"
}
},
"must": [
{
"match": {
"favo": "学习"
}
},
{
"match": {
"age": "13"
}
}
]
}
}
}
# 模糊匹配: fuzzy ,主要用来匹配英文
GET student/_search
{
"query": {
"fuzzy": {
"name": {
"value": "y00"
}
}
},
"from": 0,
"size": 2
}
# 聚合操作: aggs
GET student/_search
{
"aggs": {
"group_by_sex": {
"terms": {
"field": "sex",
"size": 2
}
},
"group_age":{
"max": {
"field": "age"
}
}
}
}
# 分页显示操作: from
## 显示第0页的2条数据
GET student/_search
{
"from": 0,
"size": 2
}
## 统计 "学习" 女 有多少人,最大年龄的是多少
GET student/_search
{
"query": {
"bool": {
"filter": {
"term": {
"favo": "学习"
}
},
"must": [
{"match": {
"sex": "男"
}}
]
}
},
"aggs": {
"group_age": {
"max": {
"field": "age"
}
}
},
"from": 0,
"size": 20
}
### -----------------------------test -------------------------------------- ###
DELETE test01
PUT test01
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
},
"age": {
"type": "integer"
}
}
}
}
GET test01/_search
PUT test01/_doc/001
{
"name": "N001",
"age": "12"
}
GET test01/_search