Forked from davidemoro/gist:431aebd16c1ba143a90c
Last active
August 29, 2015 14:20
-
-
Save rbarilani/c7e6ced562564e4f3d93 to your computer and use it in GitHub Desktop.
elastic search examples
This file contains 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
DELETE test | |
PUT /test/ | |
{ | |
"data": { | |
"properties": { | |
"state": { | |
"type": "string", | |
"index": "not_analyzed" | |
} | |
} | |
} | |
} | |
POST /test/data/ | |
{ | |
"title": "abc", | |
"state" : "public" | |
} | |
POST /test/data/ | |
{ | |
"title": "abc", | |
"state" : "private" | |
} | |
# Public search | |
GET /test/_search | |
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"query_string": { | |
"query": "abc" | |
} | |
}, | |
"filter": { | |
"bool": { | |
"must_not": [ | |
{ | |
"term": { | |
"state": "private" | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
.. I expect one result SUCCESS | |
GET /test/_search | |
{ | |
"query": { | |
"query_string": { | |
"query": "public" | |
} | |
} | |
} | |
... I expect zero results FAIL | |
actual is: | |
{ | |
"took": 2, | |
"timed_out": false, | |
"_shards": { | |
"total": 5, | |
"successful": 5, | |
"failed": 0 | |
}, | |
"hits": { | |
"total": 1, | |
"max_score": 0.19178301, | |
"hits": [ | |
{ | |
"_index": "test", | |
"_type": "data", | |
"_id": "AU00EtV3zAVfvejek9i_", | |
"_score": 0.19178301, | |
"_source": { | |
"title": "abc", | |
"state": "public" | |
} | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment