ElasticSearch(五)之elasticsearch基本用法

這些用法是基於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" }
}
}
}
}
}
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章