es–基础–04–restful接口访问
1、es的接口语法
二、索引index
2.1、创建索引
2.1.1、创建索引
2.1.2、效果
http://60.205.188.229:9200/blog2
2.2、删除索引
3、Mapping
3.1、先创建索引再创建Mapping
- 我们可以在创建索引时设置mapping信息,当然也可以先创建索引然后再设置mapping。
3.1.1、先创建索引
http://60.205.188.229:9200/blog3
3.1.2、再创建Mapping
3.1.3、效果
http://60.205.188.229:9200/blog3/hello/_mapping
{
"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.2、创建索引并创建Mapping
http://60.205.188.229:9200/blog4
{
"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"
}
}
}
}
}
4、文档document
4.1、创建文档
我们在刚刚创建的索引中创建文档
http://60.205.188.229:9200/blog4/article/1
{
"id":1,
"title":"title1",
"content":"content1"
}
4.1.1、效果
4.2、修改文档
4.3、删除文档
4.4、查询文档
4.4.1、创建多个文档
4.4.2、根据id查询
4.4.3、querystring查询
- 会分词查询
http://60.205.188.229:9200/blog4/article/_search
{
"query": {
"query_string": {
"default_field": "title",
"query": "了一个分布式多用户能力的"
}
}
}
4.4.3.1、会分词查询
4.4.3、term查询
- 单个单词查询
- 关键词查询
http://60.205.188.229:9200/blog4/article/_search
{
"query": {
"term": {
"title": "title4"
}
}
}