Skip to content

Instantly share code, notes, and snippets.

@cbismuth
Last active October 29, 2018 14:32
Embed
What would you like to do?
cURL recreation script to reproduce Elaticsearch issue #34522
#!/usr/bin/env bash
# elasticsearch-issue-34522.sh
# cURL recreation script to reproduce Elaticsearch issue #34522
# https://github.com/elastic/elasticsearch/issues/34522
NL1="\n"
NL2="${NL1}${NL1}"
NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
info () {
now=$(date +"%m-%d-%y %T")
printf "[${now}] ${GREEN}$1${NL1}${NC}"
}
error () {
now=$(date +"%m-%d-%y %T")
printf "[${now}] ${RED}$1${NL1}${NC}"
}
linebreak () {
printf "${NL1}"
}
newline () {
printf "${NL2}"
}
enter() {
read -p "Enable your breakpoints and press [ENTER] to continue"
}
ES_CLUSTER="http://localhost:9200"
info "Delete [index1] index"
curl -XDELETE "${ES_CLUSTER}/index1"
newline
info "Create [index1] index"
curl -XPUT "${ES_CLUSTER}/index1" -H "Content-Type: application/json" --data '{
"mappings": {
"type1": {
"properties": {
"non_availability1": {
"type": "nested"
}
}
}
}
}'
newline
info "Create document [1] in index [index1] (with non-availabilities as {\"2018-07-01\", \"2018-07-02\"})"
curl -XPOST "${ES_CLUSTER}/index1/type1/1?refresh=true" -H "Content-Type: application/json" --data '{
"non_availability1" : [{ "date1": "2018-07-01" }, { "date1": "2018-07-02" }]
}'
newline
info "Create document [2] in index [index1] (with non-availabilities as {\"2018-08-01\", \"2018-08-02\"})"
curl -XPOST "${ES_CLUSTER}/index1/type1/2?refresh=true" -H "Content-Type: application/json" --data '{
"non_availability1" : [{ "date1": "2018-08-01" }, { "date1": "2018-08-02" }]
}'
newline
info "Create document [3] in index [index1] (without non-availabilities)"
curl -XPOST "${ES_CLUSTER}/index1/type1/3?refresh=true" -H "Content-Type: application/json" --data '{
"non_availability1" : []
}'
newline
info "Get all documents from index [index1]"
curl -XGET "${ES_CLUSTER}/index1/_search?pretty=true&q=*:*"
linebreak
info "Search documents with must_not/range/within [\"2018-07-01\", \"2018-07-03\"] query >>> docs without non-availabilities at all aren't returned"
curl -XGET "${ES_CLUSTER}/index1/_search?pretty=true" -H "Content-Type: application/json" --data '{
"query": {
"nested": {
"path": "non_availability1",
"query": {
"bool": {
"must_not": [
{
"range": {
"non_availability1.date1": {
"gte": "2018-07-01",
"lt": "2018-07-03",
"relation": "within"
}
}
}
]
}
}
}
}
}'
linebreak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment