初始Elasticsearch(一)

以下内容参考:https://es.xiaoleilu.com/index.html
Elasticsearch 权威指南(中文版)

Elasticsearch是面向文档(document oriented)的,这意味着它可以存储整个对象或文档(document)。然而它不仅仅是存储,还会索引(index)每个文档的内容使之可以被搜索。在Elasticsearch中,你可以对文档(而非成行成列的数据)进行索引、搜索、排序、过滤。这种理解数据的方式与以往完全不同,这也是Elasticsearch能够执行复杂的全文搜索的原因之一。

查询所有的用户:

GET mfloat-user/user/_search
{
  "query": {
  "match_all": {
  }
  }
}

查询所有用户的数量:

GET mfloat-user/user/_count
{
  "query": {
    "match_all": {}
  }
}

elasticsearch-验证搜索语法是否正确:

GET mfloat-user/user/_validate/query?explain
{
  "query":{
    "match": {
      "username": "李三光"
    }
  }
}

在任意的查询字符串中增加pretty将使请求返回更加美观易读的JSON数据:

GET mfloat-user/user/_count?pretty
{
  "query": {
    "match_all": {}
  }
}

查询所有的用户并按创建时间倒序排序

GET mfloat-user/user/_search
{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "createdDate": "desc"
       }
         ]
  }

分页查询用户
from:从第几个开始查 size:查询几个

  GET mfloat-user/user/_search
  {
    "query": {
      "match_all": {}
    },
    "from": 0,   
    "size": 2
  }

指定查询结果字段(field)

GET mfloat-user/user/_search
{
  "query": {
    "match_all": {}
  },
    "_source":[
      "username",
      "role"
      ]
  }

term是代表完全匹配,不进行分词器分析,文档中必须包含整个搜索的词汇
match查询匹配进行分词,所有包括虫 测 试的一个或多个数据被查询出来

GET mfinv3-financial_institution/financial_institution/_search
{
  "query": {
    "match": {
      "financialInstitutionName": "虫测试"
    }
  }
}

match_phrase则是精确匹配,并且是相邻的(虫洞)(不能是虫~洞)

GET mfinv3-financial_institution/financial_institution/_search
{
  "query": {
    "match_phrase": {
      "financialInstitutionName": "虫洞"
    }
  }
}

聚合(aggregations)

GET mfinv3-financial_institution/financial_institution/_search
    {
      "query": {
        "match": {
          "financialInstitutionName": "虫测试"
        
        }
      },
      "aggs": {
        "financialInstitutionNameAgg": {
          "terms": {
            "field": "financialInstitutionName.keyword",
            "size": 10
          }
        }
      }
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值