Skip to content

Instantly share code, notes, and snippets.

@djptek
Last active November 21, 2018 11:48
Show Gist options
  • Select an option

  • Save djptek/78ac29d82791a02ff759fa046b1e855b to your computer and use it in GitHub Desktop.

Select an option

Save djptek/78ac29d82791a02ff759fa046b1e855b to your computer and use it in GitHub Desktop.
Temas a mirar. • Eng1 ejemplo de author.company • Ver si es mas eficiente null values para aggs o no afecta. • Ver si en los metadatos de los mappings se pueden definir objetos, mappings. • Queries con range complejas, con intervalos variables.
#########
# 2018-11-21
#
########
# Ver si en los metadatos de los mappings se pueden definir objetos, mappings.
PUT test_object_in_meta/_doc/1
{
"_meta": {
"sub_1": 1,
"sub_2": "value"
}
}
GET test_object_in_meta/_search
{
"aggs": {
"sub_1_cardinality": {
"cardinality": {
"field": "_meta.sub_1"
}
}
}
}
########
# Queries con range complejas, con intervalos variables.
PUT test_multi_date_ranges
{
"mappings": {
"_doc": {
"properties": {
"my_date_ranges": {
"type": "date_range"
}
}
}
}
}
PUT test_multi_date_ranges/_doc/1
{
"my_date_ranges": [
{"gte": "2014-01-01", "lt": "2015-01-01"},
{"gte": "2016-01-01", "lt": "2017-01-01"}
]
}
##### INTERSECT OK
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2014-01-01",
"lt": "2015-01-01"
}
}
}
}
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2016-01-01",
"lt": "2017-01-01"
}
}
}
}
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2015-01-01",
"lt": "2016-01-01"
}
}
}
}
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2014-01-01",
"lt": "2017-01-01"
}
}
}
}
#####
# CONTAINS
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2014-01-01",
"lt": "2015-01-01",
"relation": "contains"
}
}
}
}
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2016-01-01",
"lt": "2017-01-01",
"relation": "contains"
}
}
}
}
# the "gap" should miss, OK
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2015-01-01",
"lt": "2016-01-01",
"relation": "contains"
}
}
}
}
# the "outer" fails, since neither range encloses this range
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2014-01-01",
"lt": "2017-01-01",
"relation": "contains"
}
}
}
}
######
# WITHIN
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2014-01-01",
"lt": "2015-01-01",
"relation": "within"
}
}
}
}
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2016-01-01",
"lt": "2017-01-01",
"relation": "within"
}
}
}
}
# the "gap" should miss, OK
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2015-01-01",
"lt": "2016-01-01",
"relation": "within"
}
}
}
}
# the "outer" succeeds, since either range is enclosed in this range
GET test_multi_date_ranges/_search
{
"query": {
"range": {
"my_date_ranges": {
"gte": "2014-01-01",
"lt": "2017-01-01",
"relation": "within"
}
}
}
}
#####
# Ver si es mas eficiente null values para aggs o no afecta.
GET _cat/indices
GET logs_server1/_mapping
PUT logs_null_url
{
"mappings": {
"_doc": {
"properties": {
"originalUrl": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
PUT _ingest/pipeline/remove-originalUrl
{
"description" : "Remove originalUrl pipeline",
"processors" : [
{
"remove" : {
"field": "originalUrl",
"ignore_failure" : true
}
}
]
}
POST _reindex
{
"source": {
"index": "logs_server*"
},
"dest": {
"index": "logs_null_url",
"pipeline": "remove-originalUrl"
}
}
PUT _ingest/pipeline/default-originalUrl
{
"description" : "Default originalUrl pipeline",
"processors" : [
{
"set" : {
"field": "originalUrl",
"value" : "DEFAULT"
}
}
]
}
POST _reindex
{
"source": {
"index": "logs_server*"
},
"dest": {
"index": "logs_default_url",
"pipeline": "default-originalUrl"
}
}
POST _reindex
{
"source": {
"index": "logs_server*"
},
"dest": {
"index": "logs_all"
}
}
GET _cat/indices
############### 1st iteration
### 469
GET logs_all/_search
{
"aggs": {
"my_terms_agg": {
"terms": {
"field": "originalUrl.keyword",
"size": 10
}
}
}
}
### 80
GET logs_default_url/_search
{
"aggs": {
"my_terms_agg": {
"terms": {
"field": "originalUrl.keyword",
"size": 10
}
}
}
}
### 69
GET logs_null_url/_search
{
"aggs": {
"my_terms_agg": {
"terms": {
"field": "originalUrl.keyword",
"size": 10
}
}
}
}
##### now overwrite logs_server1 data as is
POST _reindex
{
"source": {
"index": "logs_server1"
},
"dest": {
"index": "logs_default_url"
}
}
POST _reindex
{
"source": {
"index": "logs_server1"
},
"dest": {
"index": "logs_all"
}
}
GET _cat/
GET /_tasks?detailed=true&actions=*reindex&group_by=parents
### 394
GET logs_default_url/_search
{
"aggs": {
"my_terms_agg": {
"terms": {
"field": "originalUrl.keyword",
"size": 10
}
}
}
}
### 39
GET logs_null_url/_search
{
"aggs": {
"my_terms_agg": {
"terms": {
"field": "originalUrl.keyword",
"size": 10
}
}
}
}
##### now overwrite logs_server2 data as is
POST _reindex
{
"source": {
"index": "logs_server2"
},
"dest": {
"index": "logs_default_url"
}
}
POST _reindex
{
"source": {
"index": "logs_server2"
},
"dest": {
"index": "logs_all"
}
}
GET /_tasks?detailed=true&actions=*reindex&group_by=parents
### 197
GET logs_default_url/_search
{
"aggs": {
"my_terms_agg": {
"terms": {
"field": "originalUrl.keyword",
"size": 10
}
}
}
}
### 30
GET logs_null_url/_search
{
"aggs": {
"my_terms_agg": {
"terms": {
"field": "originalUrl.keyword",
"size": 10
}
}
}
}
# TRY SEARCH...
### 115
GET logs_default_url/_search
{
"query": {
"match": {
"originalUrl.keyword": "DEFAULT"
}
}
}
### 28
GET logs_null_url/_search
{
"query": {
"bool": {
"must_not": [
{"exists" : { "field" : "originalUrl.keyword" }}
]
}
}
}
#####
# Eng1 ejemplo de author.company
PUT my_blogs/_doc/1
{
"id": "1",
"title": "Better query execution",
"category": "Engineering",
"date":"July 15, 2015",
"author":{
"first_name": "AAA",
"last_name": "BBB",
"company": "COMPANY"
}
}
PUT my_blogs/_doc/2
{
"id": "2",
"title": "The Story of Sense",
"date":"May 28, 2015",
"author":{
"first_name": "CCC",
"last_name": "DDD"
}
}
POST my_blogs/_doc/_bulk
{"update": {"_id": 2}}
{"doc": {"category": "Engineering", "author.company":"COMPANY"}}
{"index": {"_id": 3}}
{"title":"Using COMPANY Graph","category":"Engineering","date":"May 25, 2016","author":{"first_name":"EEE","last_name":"FFF","company":"COMPANY"}}
POST my_blogs/_doc/_bulk
{"update": {"_id": 2}}
{"doc": {"category": "Engineering", "author.company":"COMPANY"}}
{"index": {"_id": 3}}
{"title":"Using COMPANY Graph","category":"Engineering","date":"May 25, 2016","author":{"first_name":"EEE","last_name":"FFF","company":"COMPANY"}}
GET my_blogs/_search
POST my_blogs/_doc/_bulk
{"update": {"_id": 2}}
{"doc": {"category": "Engineering", "author.company":"COMPANY"}}
{"index": {"_id": 3}}
{"title":"Using COMPANY Graph","category":"Engineering","date":"May 25, 2016","author":{"first_name":"EEE","last_name":"FFF","company":"COMPANY"}}
GET my_blogs/_search
{
"aggs": {
"how_many_terms": {
"terms": {
"field": "author.company.keyword",
"size": 10
}
}
}
}
POST my_blogs/_doc/_bulk
{"update": {"_id": 2}}
{"doc": {"category": "Engineering", "author":{"company":"COMPANY"}}}
{"index": {"_id": 3}}
{"title":"Using COMPANY Graph","category":"Engineering","date":"May 25, 2016","author":{"first_name":"EEE","last_name":"FFF","company":"COMPANY"}}
POST my_blogs/_doc/_bulk
{"update": {"_id": 2}}
{"doc": {"category": "Engineering", "author":{"company":"TEST"}}}
{"index": {"_id": 3}}
{"title":"Using COMPANY Graph","category":"Engineering","date":"May 25, 2016","author":{"first_name":"EEE","last_name":"FFF","company":"COMPANY"}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment