Skip to content

Instantly share code, notes, and snippets.

@huyphan
Created March 31, 2014 09:51
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 huyphan/9888959 to your computer and use it in GitHub Desktop.
Save huyphan/9888959 to your computer and use it in GitHub Desktop.
Weird behavior of Elasticsearch 1.0.1
# Delete the index if exists
$ curl -XDELETE "http://localhost:9200/sample"
{"acknowledged":true}
# Create "sample" index, with standard analyzer using comma character for tokenizing
$ curl -XPUT "http://localhost:9200/sample" -d '
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"standard" : {
"filter" : [ "lowercase" ],
"tokenizer" : "comma"
},
"default_index" : {
"filter" : [ "lowercase" ],
"tokenizer" : "comma"
}
},
"tokenizer" : {
"comma" : {
"pattern" : ",",
"type" : "pattern"
}
}
}
}
}
}
'
{"acknowledged":true}
# Add a record
$ curl -XPOST "http://localhost:9200/sample/users/1" -d'
{
"random_string" : "ABC,XYZ",
"random_number" : "123456,7890123",
"random_email" : "abc@foobar.com,abc@foobar.net"
}'
{"_index":"sample","_type":"users","_id":"1","_version":1,"created":true}
# Refresh index
$ curl -XPOST "http://localhost:9200/sample/_refresh"
{"_shards":{"total":10,"successful":10,"failed":0}}
# Try to search for 123456
$ curl -XGET "http://localhost:9200/sample/_search?q=123456"
{"took":4,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
# Now try to delete the record then add another one, same content but with one field removed:
$ curl -XDELETE "http://localhost:9200/sample/users/1"
{"found":true,"_index":"sample","_type":"users","_id":"1","_version":2}
$ curl -XPOST "http://localhost:9200/sample/users/1" -d'
{
"random_number" : "123456,7890123",
"random_email" : "abc@foobar.com,abc@foobar.net"
}'
{"_index":"sample","_type":"users","_id":"1","_version":3,"created":true}
# Refresh the index
$ curl -XPOST "http://localhost:9200/sample/_refresh"
{"_shards":{"total":10,"successful":10,"failed":0}}
# Search again with the same query
$ curl -XGET "http://localhost:9200/sample/_search?q=123456"
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.15342641,"hits":[{"_index":"sample","_type":"users","_id":"1","_score":0.15342641, "_source" :
{
"random_number" : "123456,7890123",
"random_email" : "abc@foobar.com,abc@foobar.net"
}}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment