Skip to content

Instantly share code, notes, and snippets.

@alexbrasetvik
Created December 12, 2013 12:22
Show Gist options
  • Save alexbrasetvik/7927180 to your computer and use it in GitHub Desktop.
Save alexbrasetvik/7927180 to your computer and use it in GitHub Desktop.
_id: 1
foo: null
bar: null
---
_id: 2
foo: ''
bar: ''
---
_id: 3
foo: bar
bar: baz
type:
properties:
foo:
type: string
index: not_analyzed
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"settings": {},
"mappings": {
"type": {
"properties": {
"foo": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type","_id":1}}
{"foo":null,"bar":null}
{"index":{"_index":"play","_type":"type","_id":2}}
{"foo":"","bar":""}
{"index":{"_index":"play","_type":"type","_id":3}}
{"foo":"bar","bar":"baz"}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"filtered": {
"filter": {
"term": {
"foo": ""
}
}
}
}
}
'
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"filtered": {
"filter": {
"missing": {
"field": "bar"
}
}
}
}
}
'
# Auto generated by Found's Play-tool at 2013-12-12T13:22:01+01:00
version: 0
title: empty strings vs. analysis/missing
description: ""
# This will match only the 2nd document. Note that the "foo"-field is not_analyzed
query:
filtered:
filter:
term:
foo: ''
---
# This will match both 1 and 2. For an analyzed field, there is no difference between a missing field and an empty string.
query:
filtered:
filter:
missing:
field: bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment