Elasticsearch填充
创建索引
PUT - http://localhost:9200/schools
响应
创建映射和添加数据
映射参数说明:
1.type:Elasticsearch 中支持的数据类型非常丰富。以下是数据类型:
- String类型包含
text(可分词)
和keyword(不可分词)
- Numerical类型分为两类基本数据类型
(long、integer、short、byte、double、float、half_float)
和浮点数的高精度类型scaled_float
- Date日期类型
- Array数组类型
- Object对象
2.index:是否索引,默认为true。也就是说index设为true的时候才可以被搜索
3.store:是否将数据进行独立存储,默认为 false。原始的文本会存储在_source 里面,默认情况下其他提取出来的字段都不是独立存储的,是从_source 里面提取出来的。当然你也可以独立的存储某个字段,只要设置"store": true 即可,获取独立存储的字段要比从_source 中解析快得多,但是也会占用更多的空间,所以要根据实际业务需求来设置。
4.analyzer:分词器,这里的 ik_max_word 即使用 ik 分词器
创建映射(第一种)
PUT - http://localhost:9200/schools/_mapping
{
"properties" : {
"schoolname" : {
"type" : "text",
"index" : true
},
"tel" : {
"type" : "text",
"index" : true
},
"area" : {
"type" : "double",
"index" :true
}
}
}
响应
创建映射(第二种)
PUT - http://localhost:9200/schools
{
"settings":{},
"mappings":{
"properties":{
"name": {
"type":"text",
"index":true
},
"tel" : {
"type":"text",
"index":true
},
"area" : {
"type":"double",
"index":true
}
}
}
}
添加数据
POST - http://localhost:9200/schools/_doc
{
"name":"潘家园小学",
"tel":"1822222222",
"area":875.3
}