最近在学习elasticsearch,做了一些练习,分享下练习成果,es基于6.7.2,用kibana处理DSL,有兴趣的伙伴可以自己试试
1.简单查询练习 source: test003/doc1.1 查询name中包含"li"的人,
GET test003/_search
{
"query":
{
"regexp":{"user":".*li.*"}
}
}
1.2 查询msg中含有birthday的数据,
GET test003/_search
{
"query":
{
"match":{"message":"birthday"}
}
}
1.3 查询city上海的,
GET /test003/_search
{
"query":
{
"match":{"city":"上海"}
}
}
1.4 查询name wangwu或lisi的,
GET test003/_search
{
"query":
{
"terms":{
"user":["lisi","wangwu"]
}
}
}
1.5 查询年龄大于35小于60的,同上/只显示name age city
GET test003/_search
{
"_source": ["name","age","city"],
"query":
{
"range": {
"age": {
"gt": 35,
"lt": 60
}
}
}
}
1.6 查询年龄大于30且city不在北京的,
GET test003/_search
{
"query":
{
"bool":
{
"must": [
{"range": {
"age": {
"gte": 30
}
}}
],
"must_not": [
{
"term": {
"city": "北京"
}
}
]
}
}
}
1.7 查询name不含"li"且age大于20,
GET test003/_search
{
"query":
{
"bool":
{
"must": [
{"range": {
"age": {
"gte": 20
}
}}
],
"must_not": [
{"regexp": {
"user": ".*li.*"
}}
]
}
}
}