Skip to content

Instantly share code, notes, and snippets.

@jprante
Created March 31, 2014 12:57
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 jprante/9891706 to your computer and use it in GitHub Desktop.
Save jprante/9891706 to your computer and use it in GitHub Desktop.
ES custom tokenizer and (_all) field search
curl -XDELETE "http://localhost:9200/sample"
curl -XPUT "http://localhost:9200/sample" -d '
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"comma" : {
"filter" : [ "lowercase" ],
"tokenizer" : "comma"
}
},
"tokenizer" : {
"comma" : {
"pattern" : ",",
"type" : "pattern"
}
}
}
}
},
"mappings" : {
"users" : {
"_all" : { "type" : "string", "analyzer" : "comma" },
"properties" : {
"random_string" : {
"type" : "string", "analyzer" : "comma", "include_in_all" : false
},
"random_number" : {
"type" : "string", "analyzer" : "comma", "include_in_all" : true
},
"random_email" : {
"type" : "string", "analyzer" : "comma", "include_in_all" : false
}
}
}
}
}
'
curl -XGET "http://localhost:9200/sample/users/_mapping?pretty"
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"
}'
curl -XPOST "http://localhost:9200/sample/_refresh"
curl -XGET "http://localhost:9200/sample/_search?q=123456"
curl -XGET "http://localhost:9200/sample/_search?q=random_number:123456"
curl -XDELETE "http://localhost:9200/sample/users/1"
curl -XPOST "http://localhost:9200/sample/users/1" -d '
{
"random_number" : "123456,7890123",
"random_email" : "abc@foobar.com,abc@foobar.net"
}'
curl -XPOST "http://localhost:9200/sample/_refresh"
curl -XGET "http://localhost:9200/sample/_search?q=123456"
curl -XGET "http://localhost:9200/sample/_search?q=random_number:123456"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment