RESTfull接口访问Elasticsearch

【数据库的健康值】
curl -X GET  "ip:9200/_cat/health"

【查看所有索引】
curl -X GET "ip:9200/_cat/indices?v"

【查看索引index_name】
curl -X GET "ip:9200/索引?pretty"


【创建索引/文档】
PUT "ip:9200/索引/文档id"
{请求体}

【更新文档】
POST /索引/类型/文档id/_update
{
    "doc": {
        "name": "赤羽信之戒",
        "age": 46
    }
}

【删除文档】
DELETE 索引/类型/文档Id

---------------------------------【查询文档】------------------------------
GET 索引/类型/文档id

GET 索引/类型/_search?q=name:smy

精确匹配
GET 索引/_search
{
  "query": {
    "match": {  
      "name": "任飘渺"
    }
  }
}

and 过滤

GET 索引/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "任飘渺"
          }
        },
        {
          "match": {
            "age": "40"
          }
        }
      ]
    }
  }
}

or 过滤

GET 索引/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "name": "任飘渺"
          }
        },
        {
          "match": {
            "age": "40"
          }
        }
      ]
    }
  }
}

not 过滤

GET 索引/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "match": {
            "age": "40"
          }
        }
      ]
    }
  }
}

范围过滤
GET 索引/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": "任飘渺"
          }
        }
      ],
      "filter": {
        "range": {
          "age": {
            "gt": 20,
            "lt": 40
          }
        }
      }
    }
  }
}

精确查询  精确查询是通过term关键字来实现的,他的底层是通过直接查询倒排索引,效率更高!
关于分词的解释:
(1)term:直接查询精确的
(2)match:会使用分词器(会先分析文档,然后通过分析的文档进行查询!查询效率低)

说明:如果类型是text类型,那么是可以被分词器解析的;如果是keyword类型的,是不能被分词器解析,想使用match或者term来查询这个字段匹配的,只能查询出完全匹配的数据来,其他的数据差一个字符都不能被查询出来!

GET 索引/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "name": "任飘渺"
          }
        },
        {
          "term": {
            "age": "40"
          }
        }
      ]
    }
  }
}

过滤字段

GET 索引/_search
{
  "_source":["name","age"],
  "query": {
    "match": {
      "name": "任飘渺"
    }
  }
}

排序
GET 索引/_search
{
  "query": {
    "match": {
      "name": "任飘渺"
    }
  },
  "sort": [
    {
      "age": {
        "order": "asc"
      }
    }
  ],
  "from":0,
  "size":1
}

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值