ElasticSearch基础(一):Postman操作ElasticSearch


(1)创建索引index和映射mapping

请求类型:POST

请求URL:http://127.0.0.1:9200/blog2/hello/_mapping

参数body:

{
  "mappings": {
    "article": {
      "properties": {
        "id": {
          "type": "long",
          "store": true,
          "index": "not_analyzed"
        },
        "title": {
          "type": "text",
          "store": true,
          "index": "analyzed",
          "analyzer": "standard"
        },
        "content": {
          "type": "text",
          "store": true,
          "index": "analyzed",
          "analyzer": "standard"
        }
      }
    }
  }
}

(2)为blog2索引设置mapping(前提:需要先创建索引blog2)

请求类型:POST

请求URL:http://127.0.0.1:9200/blog2/hello/_mapping

参数body:

{
  "hello": {
    "properties": {
      "id": {
        "type": "long",
        "store": true
      },
      "title": {
        "type": "text",
        "store": true,
        "index": true,
        "analyzer": "standard"
      },
      "content": {
        "type": "text",
        "store": true,
        "index": true,
        "analyzer": "standard"
      }
    }
  }
}

(3)删除索引blog2

请求类型:DELETE

请求URL:http://127.0.0.1:9200/blog2

参数body:


(4)创建文档document

请求类型:POST

请求URL:http://127.0.0.1:9200/blog1/article/1

参数body:

{
  "id": 1,
  "title": "ElasticSearch是一个基于Lucene的搜索服务器",
  "content": "它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。"
}

(5)修改文档document

请求类型:POST

请求URL:http://127.0.0.1:9200/blog1/article/1

参数body:

{
  "id": 1,
  "title": "【修改版】ElasticSearch是一个基于Lucene的搜索服务器",
  "content": "【修改版】它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。"
}

(6)删除文档document

请求类型:DELETE

请求URL:http://127.0.0.1:9200/blog1/article/2

注: 删除id为2的文档。

参数body:


(7)查询文档(根据id查询)

请求类型:GET

请求URL:http://127.0.0.1:9200/blog1/article/1

参数body:


(8)查询文档(querystring查询)

请求类型:GET

请求URL:http://127.0.0.1:9200/blog1/article/_search

参数body:

{
  "query": {
    "query_string": {
      "default_field": "title",
      "query": "搜索服务器"
    }
  }
}

(9)查询文档(term查询)

请求类型:GET

请求URL:http://127.0.0.1:9200/blog1/article/_search

参数body:

{
  "query": {
    "term": {
      "title": "搜索"
    }
  }
}

(10)ElasticSearch标准分词器分词效果

请求类型:GET

请求URL:http://127.0.0.1:9200/_analyze?analyzer=standard&pretty=true&text=我是程序员

参数body:


(11)IK分词器测试(ik_smart最少切分算法)

请求类型:GET

请求URL:http://127.0.0.1:9200/_analyze?analyzer=ik_smart&pretty=true&text=我是程序员

参数body:


(12)IK分词器测试(ik_max_word最细粒度划分算法)

请求类型:GET

请求URL:http://127.0.0.1:9200/_analyze?analyzer=ik_max_word&pretty=true&text=我是程序员

参数body:


(13)创建索引blog2(使用IK分词器的ik_max_word最细粒度划分算法)

请求类型:PUT

请求URL:http://localhost:9200/blog2

参数body:

{
  "mappings": {
    "article": {
      "properties": {
        "id": {
          "type": "long",
          "store": true,
          "index": "not_analyzed"
        },
        "title": {
          "type": "text",
          "store": true,
          "index": "analyzed",
          "analyzer": "ik_max_word"
        },
        "content": {
          "type": "text",
          "store": true,
          "index": "analyzed",
          "analyzer": "ik_max_word"
        }
      }
    }
  }
}

(14)为索引blog2创建文档

请求类型:POST

请求URL:http://localhost:9200/blog2/article/1

参数body:

{
  "id": 1,
  "title": "ElasticSearch是一个基于Lucene的搜索服务器",
  "content": "Elasticsearch是用Java开发的,实时搜索,稳定,可靠,快速,安装使用方便。"
}

(15)通过queryString查询文档(测试IK分词器)

请求类型:GET

请求URL:http://localhost:9200/blog2/article/_search

参数body:

{
  "query": {
    "query_string": {
      "default_field": "title",
      "query": "钢索"
    }
  }
}

(16)通过term查询文档(测试IK分词器)

请求类型:GET

请求URL:http://localhost:9200/blog2/article/_search

参数body:

{
  "query": {
    "term": {
      "title": "搜索"
    }
  }
}

(17)集群:创建索引 blog1

请求类型:PUT

请求URL:http://localhost:9200/blog1

参数body:

{
  "mappings": {
    "article": {
      "properties": {
        "id": {
          "type": "long",
          "store": true,
          "index": "not_analyzed"
        },
        "title": {
          "type": "text",
          "store": true,
          "index": "analyzed",
          "analyzer": "ik_max_word"
        },
        "content": {
          "type": "text",
          "store": true,
          "index": "analyzed",
          "analyzer": "ik_max_word"
        }
      }
    }
  }
}

(18)集群:为索引blog1添加文档

请求类型:POST

请求URL:localhost:9200/blog1/article/1

参数body:

{
  "id": 1,
  "title": "ElasticSearch是一个基于Lucene的搜索服务器",
  "content": "它提供了一个分布式多用户能力的全文搜索引擎,实时搜索,稳定,可靠,快速,安装使用方便。"
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值