zoukankan      html  css  js  c++  java
  • elasticsearch简单操作

    查看所有index

    curl -X GET 'localhost:9200/_cat/indices?v'
    

    查看每个index所有的type

    curl 'localhost:9200/_mapping?pretty=true'
    

    新建index

    curl -X PUT 'localhost:9200/weather'
    

    删除index

    curl -X DELETE 'localhost:9200/weather'
    

    新建index并指定要分词的字段(accounts是index,person是type,person有三个字段)

    curl -X PUT 'localhost:9200/accounts' -d '
    {
      "mappings": {
        "person": {
          "properties": {
            "user": {
              "type": "text",
              "analyzer": "ik_max_word",
              "search_analyzer": "ik_max_word"
            },
            "title": {
              "type": "text",
              "analyzer": "ik_max_word",
              "search_analyzer": "ik_max_word"
            },
            "desc": {
              "type": "text",
              "analyzer": "ik_max_word",
              "search_analyzer": "ik_max_word"
            }
          }
        }
      }
    }'
    

    index里新增document

    curl -X PUT 'localhost:9200/accounts/person/1' -d '
    {
      "user": "张三",
      "title": "工程师",
      "desc": "数据库管理"
    }'
    

    查看记录

    curl 'localhost:9200/accounts/person/1?pretty=true'
    

    删除记录

    curl -X DELETE 'localhost:9200/accounts/person/1'
    

    查看所有记录

    curl 'localhost:9200/accounts/person/_search'
    

    查找(通过from和size指定位移,分页操作)

    curl 'localhost:9200/accounts/person/_search'  -d '
    {
      "query" : { "match" : { "desc" : "管理" }},
      "from": 1,
      "size": 1
    }'
    

    多个关键字搜索(or)

    curl 'localhost:9200/accounts/person/_search'  -d '
    {
      "query" : { "match" : { "desc" : "管理" }},
      "from": 1,
      "size": 1
    }'
    

    多个关键词搜索(and)

    curl 'localhost:9200/accounts/person/_search'  -d '
    {
      "query": {
        "bool": {
          "must": [
            { "match": { "desc": "软件" } },
            { "match": { "desc": "系统" } }
          ]
        }
      }
    }'
  • 相关阅读:
    PHP用腾讯地图api根据地址获取经纬度的方法
    Tomcat实现负载均衡
    命令行备忘神器 Navi
    Bashtop – Linux的资源监视工具
    使用jinfo出现“can't determine target's VM version”问题解决方法
    axios 封装【满足常规数据上传及file上传】
    前端基础之设计模式篇
    使用Chrome插件拦截广告的原理
    前端基础之算法篇
    一道面试题引发的思考
  • 原文地址:https://www.cnblogs.com/wswang/p/10895133.html
Copyright © 2011-2022 走看看