Skip to content

Instantly share code, notes, and snippets.

@EdgeCaseBerg
Last active November 10, 2016 19:10
Show Gist options
  • Save EdgeCaseBerg/8a69688f087f601a382951eab1910120 to your computer and use it in GitHub Desktop.
Save EdgeCaseBerg/8a69688f087f601a382951eab1910120 to your computer and use it in GitHub Desktop.
Example of how to use copy_to in a reg-ex individual word or full string search
PUT example_copy
{
"mappings": {
"example" : {
"properties": {
"original" : {
"type": "string",
"copy_to": "copied"
},
"copied" : {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
POST /example_copy/example
{
"original" : "hello there friend"
}
# See that the copied field doesn't show up in the _source
POST /example_copy/_search
# Gets 1 result
POST /example_copy/_search
{
"query": {
"regexp" : {
"original" : {
"value" : "t.*"
}
}
}
}
# Gets 0 results
POST /example_copy/_search
{
"query": {
"regexp" : {
"copied" : {
"value" : "t.*"
}
}
}
}
# Gets 1 result
POST /example_copy/_search
{
"query": {
"regexp" : {
"copied" : {
"value" : "h.*"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment