(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": "它提供了一个分布式多用户能力的全文搜索引擎,实时搜索,稳定,可靠,快速,安装使用方便。"
}