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"
    }
  }
}

分词器

原文地址:https://www.cnblogs.com/jarjune/p/14153567.html