Created
December 12, 2013 12:22
-
-
Save alexbrasetvik/7927180 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_id: 1 | |
foo: null | |
bar: null | |
--- | |
_id: 2 | |
foo: '' | |
bar: '' | |
--- | |
_id: 3 | |
foo: bar | |
bar: baz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type: | |
properties: | |
foo: | |
type: string | |
index: not_analyzed | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" | |
} | |
} | |
} | |
} | |
} | |
' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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