ES DSL

GET movie_index/movie/3

PUT movie_index/movie/3
{
  "id": "3",
  "name": "incident red sea",
  "doubanScore": "5.0",
  "actorList": [
    {
      "id": "1",
      "name": "zhang chen"
    }
  ]
}

POST movie_index/movie/3/_update
{
  "doc":{
    "doubanScore": "9.9"
  }
}

DELETE movie_index/movie/3

GET movie_index/movie/_search

GET movie_index/movie/_search
{
  "query":{
    "match": {"name": "red"}
  }
}

GET movie_index/movie/_search
{
  "query":{
    "match_phrase":{
      "name": "operation red"
    }
  }
}

GET movie_index/movie/_search
{
  "query":{
    "fuzzy":{
      "name": "sea"
    }
  }
}

GET movie_index/movie/_search
{
  "query": {
    "match": {
      "name": "red"
    }
  },"post_filter": {
    "term":{
      "actorList.id": 3
    }
  }
}

## 查询后过滤
GET movie_index/movie/_search
{
  "query": {
    "bool": {
      "filter": {"term": {
        "actorList.id": 1
      }},
      "must": {
        "match":{
          "name": "red"
        }
      }
    }
  }
}

## 范围过滤
## gt gte greater than or equal
## lt lte less than or equal
GET movie_index/movie/_search
{
   "query": {
     "bool": {
       "filter": {
         "range": {
            "doubanScore": {"gte": 8}
         }
       }
     }
   }
}

## 排序
GET movie_index/movie/_search
{
  "query":{
    "match": {"name":"red sea"}
  }
  , "sort": [
    {
      "doubanScore": {
        "order": "desc"
      }
    }
  ]
}

## 分页查询
GET movie_index/movie/_search
{
  "query": { "match_all": {} },
  "from": 1,
  "size": 1
}

## 指定字段
GET movie_index/movie/_search
{
  "query": {
    "match_all": {}
  },
  "_source": [
    "name",
    "doubanScore"
  ]
}

## 聚合
GET movie_index/movie/_search
{
  "aggs": {
    "groupby_actor": {
      "terms": {
        "field": "actorList.name.keyword"
      }
    }
  }
}

GET movie_index/movie/_search
{ 
  "aggs": {
    "groupby_actor_id": {
      "terms": {
        "field": "actorList.name.keyword" ,
        "order": {
          "avg_score": "desc"
          }
      },
      "aggs": {
        "avg_score":{
          "avg": {
            "field": "doubanScore" 
          }
        }
       }
    } 
  }
}
上一篇:Autosar DCM 诊断(Diagnostic Communication Manager)


下一篇:强化学习系列(一):强化学习简介