Elasticsearch查询数据常用语句

过滤同一字段多个值,用逗号分隔

"must_not": [
                        {
                            "match": {
                                "classify.second": "预告片,电影特辑,创意剪辑,片花,片段(盘点),策划,花絮"
                            }
                        }
                    ]

单条件查询,以下两种查询结果相同

GET cms_5/_search
{
  "query":{
    "bool": {
      "must": [
        {"match": {
          "year": "2018"
        }}
      ]
    }
  }
}

GET cms_5/_search
{
  "query": {
    "term": {
      "year": {
        "value": "2017"
      }
    }
  }
}

多条件查询:

1.一个查询条件,条件值有多个,类似sql语句的in

GET cms_5/_search
{
  "query": {
    "terms": {
      "year": [
        "2017",
        "2018",
        "2019"
      ]
    }
  },
  "sort": [
    {
      "contentId": {
        "order": "desc"
      }
    }
  ]
}

2.多条件查询,有必须满足的条件和必须不满足的条件

GET cms_test2/_search
{
  "query": {
    "bool": {
      "must":{"match":{"age":"50"}},
      "must_not":{"match":{"sex":"女"}}
    }
  },
  "from" : 0,
  "size" : 5
}

3.多条件查询,必须满足条件多个

GET cms_bak/_search
{
  "query":{
    "bool":{
      "must":[
        {"term":{"classify.second":"预告片"}},
        {"term": {
          "year": {
            "value": "2020"
          }
        }},
        {"term": {
          "area": {
            "value": "内地"
          }
        }},
        {"term": {
          "channelCode": {
            "value": "50000138"
          }
        }}]
    }
  }
}

聚合函数查询:

查询最大值

GET testa/_search
{
  "aggs": {
    "max_value": {
      "max": {
        "field": "age"
      }
    }
  }
}

平均值

GET testa/_search
{
  "aggs": {
    "ang": {
      "avg": {
        "field": "age"
      }
    }
  }
}

按年龄分组统计

GET testa/_search
{
  "aggs": {
    "terms_value": {
      "terms": {
        "field": "age",
        "size": 10
      }
    }
  }
}

修改某一条数据中某一字段的值:

POST indexName/_doc/22740535/_update
{
  "doc": {
    "name":"测试1234"
  }
}

修改某一索引库可查询的最大数据量

PUT indexName/_settings
{
  "index":{
    "max_result_window":"10000"
  }
}

从某一索引库复制数据到另一个索引库

POST _reindex
{
  "source": {
    "index":"indexA"
  },
  "dest": {
    "index":"indexB"
  }
}

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值