Skip to content

Instantly share code, notes, and snippets.

@ppearcy
Created September 21, 2011 17:44
Show Gist options
  • Save ppearcy/1232772 to your computer and use it in GitHub Desktop.
Save ppearcy/1232772 to your computer and use it in GitHub Desktop.
Create index:
curl -XPUT 'http://localhost:9200/my_twitter1/' -d '
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"tweet" : {
"properties" : {
"user" : {"type" : "string", "index" : "not_analyzed"},
"message" : {"type" : "string", "null_value" : "na", "index" : "analyzed", "analyzer" : "whitespace"},
"_all" : {"type" : "string", "null_value" : "na", "index" : "analyzed", "analyzer" : "whitespace"},
"postDate" : {"type" : "date"}
}
}
}
}'
Add a doc:
curl -XPUT 'http://localhost:9200/my_twitter1/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2011-09-20T16:20:00",
"message" : "I was trying to use elastic search"
}'
Run a search:
curl -X GET http://localhost:9200/my_twitter1/tweet/_search?search_type=dfs_query_and_fetch -d '{
"query": {
"query_string": {
"default_field": "_all",
"query": "was"
}
},
"from": 0,
"size": 60,
"explain": false
}'
The document does not come back as "was" gets stripped from the input since the whitepace analyzer isn't used.
Specify the analyzer and the doc comes back:
curl -X GET http://localhost:9200/my_twitter1/tweet/_search?search_type=dfs_query_and_fetch -d '{
"query": {
"query_string": {
"default_field": "_all",
"query": "was",
"analyzer": "whitespace"
}
},
"from": 0,
"size": 60,
"explain": false
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment