Skip to content

Instantly share code, notes, and snippets.

@Lokey92
Created May 18, 2022 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lokey92/c9642c36e5d95675b979ac21a2bc61d7 to your computer and use it in GitHub Desktop.
Save Lokey92/c9642c36e5d95675b979ac21a2bc61d7 to your computer and use it in GitHub Desktop.
Test functionality of doc-value-only fields introduced in Elastic ver 8
# TEST: Use case of doc-value-only fields on search and aggregation.
# CONCLUSION: Aggregations and search are both readily supported on fields with doc_values disabled. There is a performance impact but storage is better. Ideally use this feature where search speed isn't important.
# DOCUMENTATION: https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html
# NOTES: Included a disabled doc value ("doc_values: false") field for reference to aggs. Aggs do not work on them.
# Copy/paste this into Kibana > Dev Tools to try it out yourself.
# Mapping doc-value-only fields, session_id and integer are both doc-value-only.
PUT my-index-000001
{
"mappings": {
"properties": {
"status_code": {
"type": "keyword"
},
"session_id": {
"type": "keyword",
"doc_values": false
},
"meeting_id": {
"type": "keyword",
"index": false
},
"integer": {
"type": "long",
"index": false
}
}
}
}
# Put some data in it.
PUT my-index-000001/_bulk
{"create": {}}
{"status_code": "0105", "session_id": "365", "meeting_id": "117", "integer": 3}
{"create": {}}
{"status_code": "0106", "session_id": "365", "meeting_id": "117", "integer": 4}
{"create": {}}
{"status_code": "0107", "session_id": "365", "meeting_id": "117", "integer": 5}
{"create": {}}
{"status_code": "0108", "session_id": "314", "meeting_id": "118", "integer": 7}
{"create": {}}
{"status_code": "0109", "session_id": "375", "meeting_id": "121", "integer": 11}
{"create": {}}
{"status_code": "0110", "session_id": "375", "meeting_id": "121", "integer": 14}
# Simple terms search, works.
GET my-index-000001/_search
{
"query": {
"terms": {
"session_id": [ "365", "375" ],
"boost": 1.0
}
}
}
# Simple match search, works.
GET my-index-000001/_search
{
"query": {
"match": {
"session_id": "365"
}
}
}
# Boolean search, works.
GET my-index-000001/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"session_id": "375"
}
},
{
"match": {
"integer": 14
}
}
]
}
}
}
# Boolean search with filter, works.
GET my-index-000001/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"integer": "14"
}
}
],
"filter": [
{
"term": {
"session_id": "375"
}
}
]
}
}
}
# Bucket agg on meeting_id, does work as doc_value_only.
GET my-index-000001/_search
{
"size": 0,
"aggs": {
"Count": {
"terms": {
"field": "meeting_id",
"size": 10
}
}
}
}
# Bucket agg on session_id, does not work because doc_values is disabled.
GET my-index-000001/_search
{
"aggs": {
"Count": {
"terms": {
"field": "session_id",
"size": 10
}
}
}
}
# Metric agg, works.
GET my-index-000001/_search
{
"size": 0,
"aggs": {
"Sum": {
"sum": {
"field": "integer"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment