elasticsearch索引_source index store doc_values 参数实例
所属分类 elasticsearch
浏览量 3430
elasticsearch版本7.0
PUT myblog
{
"settings" : {
"number_of_shards" : 1,
"number_of_replicas" : 0 ,
"codec":"best_compression",
"index.store.type":"niofs"
},
"mappings": {
"dynamic":"strict",
"_source":{"enabled":true},
"properties": {
"id":{"type": "long"},
"title":{"type": "text"},
"category":{"type":"keyword"},
"category_store":{"type":"keyword","store":true},
"category_no_store":{"type":"keyword","store":false},
"category_no_index":{"type":"keyword","index":false},
"category_no_doc_values":{"type":"keyword","doc_values": false},
"content":{"type":"text"},
"postdate":{"type": "date"},
"time":{"type":"long"},
"time_no_index":{"type":"long","index":false},
"time_no_doc_values":{"type":"long","doc_values": false},
"score":{"type":"double"},
"score_no_index":{"type":"double","index":false},
"score_no_doc_values":{"type":"double","doc_values": false}
}
}
}
索引已存在会报错 resource_already_exists_exception
dynamic
true 默认值为true,自动添加字段
false 忽略新的字段
strict 严格模式,发现新的字段抛出异常
{
"type": "strict_dynamic_mapping_exception",
"reason": "mapping set to strict, dynamic introduction of [x] within [_doc] is not allowed"
}
添加测试数据
post myblog/_doc/1
{
"id":1,
"title":"hello,elasticsearch",
"content":"elasticsearch is good",
"postdate":"2019-04-17",
"category":"es",
"category_store":"es",
"category_no_store":"es",
"category_no_index":"es",
"category_no_doc_values":"es",
"time":"1",
"time_no_index":"1",
"time_no_doc_values":"1",
"score":"1.0",
"score_no_index":"1.0",
"score_no_doc_values":"1.0"
}
post myblog/_doc/2
{
"id":2,
"title":"hello,elasticsearch",
"content":"elasticsearch is good",
"postdate":"2019-04-17",
"category":"es",
"category_store":"es",
"category_no_store":"es",
"category_no_index":"es",
"category_no_doc_values":"es",
"time":"2",
"time_no_index":"2",
"time_no_doc_values":"2",
"score":"2.0",
"score_no_index":"2.0",
"score_no_doc_values":"2.0"
}
post myblog/_doc/3
{
"id":3,
"title":"hello,kafka",
"content":"kafka is good",
"postdate":"2019-04-17",
"category":"kafka",
"category_store":"kafka",
"category_no_store":"kafka",
"category_no_index":"kafka",
"category_no_doc_values":"kafka",
"time":"3",
"time_no_index":"3",
"time_no_doc_values":"3",
"score":"3.0",
"score_no_index":"3.0",
"score_no_doc_values":"3.0"
}
_source禁用后 查询时不会返回 source
post myblog/update/1
{
"title":"hello,elasticsearch2"
}
Can't merge because of conflicts: [Cannot update enabled setting for [_source]]
POST myblog/_update/1
{
"doc":{
"title":"hello,elasticsearch2"
}
}
document_source_missing_exception
_sql?format=txt
{
"query": "SELECT * FROM myblog where category_no_index ='es' "
}
Cannot search on field [category_no_index] since it is not indexed.
"failed to create query: {
"term" : {
"time_no_index" : {
"value" : 1.1,
"boost" : 1.0
}
}
}"
SELECT * FROM myblog where time_no_index = 1
只有索引字段才能查询
SELECT * FROM myblog order by time_no_index desc
这个语句可以执行 , 没有索引,但是开启了 doc_values,因此可以 排序
SELECT * FROM myblog order by time_no_doc_values desc
Can't load fielddata on [time_no_doc_values] because fielddata is unsupported on fields of type [long]. Use doc values instead.
只有 开启doc_values 才能 排序 聚合
测试 禁用 source 时 是否可以使用 sql 查询
select * from myblog
unable to fetch fields from _source field: _source is disabled in the mappings for index [myblog]
查询store 字段
select category_store from myblog
执行OK
select category_no_index from myblog
执行OK
select category_no_store from myblog
执行OK
select time,time_no_index from myblog
执行OK
select time,time_no_index,time_no_doc_values from myblog
执行失败
unable to fetch fields from _source field: _source is disabled in the mappings for index [myblog]
查询索引的字段
select id,postdate,category from myblog
可正常执行
select id,title,postdate,category from myblog
加上title 无法执行
"norms":false
Mapping definition for [time] has unsupported parameters: [norms : false]
上一篇
下一篇
elasticsearch7安装配置使用
银行理财风险等级
HTTP协议中PUT和POST的区别
elasticsearch term match match_phrase 区别
postman中form-data x-www-form-urlencoded raw binary的区别
elasticsearch term 和 match