这些用法是基于elasticsearch6.42 版本测试的不同版本语法有差别
1.创建用户有则覆盖
http://47.105.74.94:9200/department/employee/1
{
"first_name" : "姜",
"last_name" : "绵岳",
"age" : 150,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}
返回结果
{
"_index": "department",
"_type": "employee",
"_id": "1",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
2.查看用户
http://47.105.74.94:9200/department/employee/1
3.查询
http://47.105.74.94:9200/department/employee/_search
4.分词查找
http://47.105.74.94:9200/department/employee/_search?q=last_name:绵岳
5.使用DSL语句查询
http://47.105.74.94:9200/department/employee/_search
{
"query" : {
"match" : {
"last_name" : "绵岳"
}
}
}
{
"query" : {
"match" : {
"about" : "rock climbing"
}
}
}
6.过滤器
http://47.105.74.94:9200/department/employee/_search
{
"query": {
"bool": {
"must": { "match_all": {} },
"filter": {
"range": {
"age": {
"gte": 30,
"lte": 300
}
}
}
}
}
}
7.group by 操作必须执行mapping操作
http://47.105.74.94:9200/department/_mapping/employee/
{
"properties": {
"interests": {
"type": "text",
"fielddata": true
}
}
}
http://47.105.74.94:9200/department/employee/_search
{
"aggs": {
"all_interests": {
"terms": { "field": "interests" }
}
}
}
平均年龄
{
"aggs" : {
"all_interests" : {
"terms" : { "field" : "interests" },
"aggs" : {
"avg_age" : {
"avg" : { "field" : "age" }
}
}
}
}
}