- ElasticSearch doc_values、index以及
- Elasticsearch的index、doc_values以及
- Elasticsearch Index
- 【Elasticsearch】index [index] blo
- Instructions for setting up the
- Elasticsearch 存储设计与MySQL数据同步方案
- 【ES实践篇三:ES Restful Web API使用】
- 【es】Elasticsearch 的 Shard Alloca
- 【Elasticsearch 7 探索之路】(二)文档的 CRU
- Elasticsearch Shard Allocation机制
测试index、doc_values以及_source的作用
template
{
"order": 0,
"index_patterns": [
"baiyxtest*"
],
"settings": {
"index": {
"number_of_shards": "2",
"number_of_replicas": "1"
}
},
"mappings": {
"_source": {
"enabled": false
},
"properties": {
"aggable": {
"index": "false",
"type": "keyword",
"doc_values": true
},
"value": {
"type": "long",
"doc_values": false
},
"searchable": {
"type": "keyword",
"doc_values": false
}
}
},
"aliases": {}
}
1、测试index为false的字段作为检索条件
{
"query": {
"match": {
"aggable": "aaa"
}
}
}
会报错
"reason": "Cannot search on field [aggable] since it is not indexed."
2、测试index为true的字段作为检索条件
{
"query": {
"match": {
"searchable": "bbb"
}
}
}
可以查得出来,但是设置了"_source":"false",所以看不到具体文档。
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.2876821,
"hits": [{
"_index": "baiyxtest",
"_type": "_doc",
"_id": "1gno53ABNKWqmzmcZdA_",
"_score": 0.2876821
}]
}
}
3、测试doc_values为false的字段做聚合维度字段
{
"query": {
"match": {
"searchable": "bbb"
}
},
"aggregations": {
"group_by_aggable": {
"terms": {
"field": "searchable"
},
"aggregations": {
"value": {
"sum": {
"field": "value"
}
}
}
}
}
}
报错
"reason": "Can't load fielddata on [searchable] because fielddata is unsupported on fields of type [keyword]. Use doc values instead."
4、测试doc_values为false的字段做聚合数值字段
{
"query": {
"match": {
"searchable": "bbb"
}
},
"aggregations": {
"group_by_aggable": {
"terms": {
"field": "aggable"
},
"aggregations": {
"value": {
"sum": {
"field": "value"
}
}
}
}
}
}
报错
"reason": "Can't load fielddata on [value] because fielddata is unsupported on fields of type [long]. Use doc values instead."
5、修改mapping,去掉value字段的doc_values(默认值true)
{
"order": 0,
"index_patterns": [
"baiyxtest*"
],
"settings": {
"index": {
"number_of_shards": "2",
"number_of_replicas": "1"
}
},
"mappings": {
"_source": {
"enabled": false
},
"properties": {
"aggable": {
"index": "false",
"type": "keyword",
"doc_values": true
},
"value": {
"type": "long"
},
"searchable": {
"type": "keyword",
"doc_values": false
}
}
},
"aliases": {}
}
正常,返回aggable的值,且可以返回aggrable的值,说明正排索引跟_source控制的存储不一样。
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.2876821,
"hits": [{
"_index": "baiyxtest",
"_type": "_doc",
"_id": "-bD453ABNKWqmzmc4zq2",
"_score": 0.2876821
}]
},
"aggregations": {
"group_by_aggable": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [{
"key": "aaa",
"doc_count": 1,
"value": {
"value": 123
}
}]
}
}
}
网友评论