Skip to content

Instantly share code, notes, and snippets.

@m-brown
Last active August 29, 2015 14:01
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 m-brown/59b9b5ad6f68a5d12d0a to your computer and use it in GitHub Desktop.
Save m-brown/59b9b5ad6f68a5d12d0a to your computer and use it in GitHub Desktop.
# setup
curl -XDELETE 'http://localhost:9200/test'
curl -XPUT 'http://localhost:9200/test/'
curl -XPUT 'http://localhost:9200/test/document/_mapping' -d '
{
"document" : {
"dynamic": "strict",
"properties" : {
"field1" : {"type" : "string", "store" : true }
}
}
}
'
# test data
curl -XPOST 'http://localhost:9200/test/document/' -d '{"field1": "foo"}'
curl -XPOST 'http://localhost:9200/test/document/' -d '{"field1": "foo bar"}'
curl -XPOST 'http://localhost:9200/test/document/' -d '{"field1": "bar foo"}'
curl -XPOST 'http://localhost:9200/test/document/' -d '{"field1": "foo foo bar"}'
curl -XPOST 'http://localhost:9200/test/document/' -d '{"field1": "foo bar foo"}'
curl -XPOST 'http://localhost:9200/test/document/' -d '{"field1": "bar foo foo"}'
# Query to find docs with foo but not bar.
# Should return 1 doc but returns 'foo' and 'bar foo foo'
curl 'http://localhost:9200/test/_search?pretty=true' -d '
{
"query": {
"span_not": {
"include": {
"span_term": {
"field1": "foo"
}
},
"exclude": {
"span_near": {
"in_order": false,
"clauses": [
{
"span_term": {
"field1": "bar"
}
},
{
"span_term": {
"field1": "foo"
}
}
],
"slop": 1000
}
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment