elasticsearch官方文档摸索

index

创建索引

PUT google

映射mapping(注意 mapping不能修改)

include_type_name,请求体中是否包含type,高版本中会移除type
Elasticsearc 6.x以后不再支持mapping下多个type,并且 6.x 版本type默认都是 _doc,7.0以后版本将会删除type

PUT /{index} 有type (deprecated)

PUT google/user/_mapping?include_type_name=true
{
  "user": {
    "properties": {
      "name": {
        "type": "text"
      },
      "user_name": {
        "type": "keyword"
      },
      "email": {
        "type": "keyword"
      }
    }
  }
}

PUT /{index} 没type,默认type为_doc

PUT google/_mapping
{
  "properties": {
    "name": {
      "type": "text"
    },
    "user_name": {
      "type": "keyword"
    },
    "email": {
      "type": "keyword"
    }
  }
}

创建索引+映射mapping

PUT /{index} 有type (deprecated)

PUT twitter?include_type_name=true
{
  "mappings": {
    "user": {
      "properties": {
        "name": {
          "type": "text"
        },
        "user_name": {
          "type": "keyword"
        },
        "email": {
          "type": "keyword"
        }
      }
    }
  }
}

PUT /{index} 没type,默认type为_doc

PUT weibo
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      },
      "user_name": {
        "type": "keyword"
      },
      "email": {
        "type": "keyword"
      }
    }
  }
}

删除索引

DELETE google

Document

创建文档

PUT /{index}/{type}/{id} (deprecated)

PUT twitter/user/kimchy
{
  "name": "Shay Banon",
  "user_name": "kimchy",
  "email": "shay@kimchy.com"
}

PUT /{index}/_doc/{id}

PUT twitter/_doc/sharry
{
  "name": "Shay sharry",
  "user_name": "sharry",
  "email": "shay@sharry.com"
}

修改文档

POST /{index}/_update/{id}

POST twitter/_update/sharry
{
  "doc": {
    "name": "Shay sharry3"
  }
}

删除文档

DELETE /{index}/{type}/{id} (deprecated)

DELETE /twitter/user/kimchy

DELETE /{index}/_doc/{id}

DELETE /twitter/_doc/sharry

查询文档

根据id查询

GET /{index}/{type}/{id} (deprecated)
GET /twitter/user/kimchy
GET /{index}/_doc/{id}
GET /twitter/_doc/sharry

根据queryString查询

POST /{index}/{type}/_search (deprecated)
POST /twitter/user/_search
{
  "query": {
    "query_string": {
      "default_field": "user_name",
      "query": "sharry1"
    }
  }
}
POST /{index}/_search
POST /twitter/_search
{
  "query": {
    "query_string": {
      "default_field": "user_name",
      "query": "sharry1"
    }
  }
}

根据term查询

POST /{index}/{type}/_search (deprecated)
POST /twitter/user/_search
{
  "query": {
    "term": {
      "query": "sharry1"
    }
  }
}
POST /{index}/_search
POST /twitter/_search
{
  "query": {
    "term": {
      "query": "sharry1"
    }
  }
}

分词器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值