Skip to content

Instantly share code, notes, and snippets.

@fernandojmartin
Created April 4, 2013 14:50
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 fernandojmartin/5311012 to your computer and use it in GitHub Desktop.
Save fernandojmartin/5311012 to your computer and use it in GitHub Desktop.
The mapping and the user object
// MAPPING
curl -XGET http://localhost:9200/directorio/_mapping?pretty=true
{
"usuario" : {
"properties" : {
"avatar" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs"
},
"friends" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs"
},
"friends_qty" : {
"type" : "integer"
},
"iduser" : {
"type" : "integer"
},
"username" : {
"type" : "string",
"index" : "not_analyzed",
"omit_norms" : true,
"index_options" : "docs"
}
}
}
}
// THE DOCUMENT
curl -XGET http://localhost:9200/directorio/usuario/320292?pretty=true
{
"_index" : "directorio",
"_type" : "usuario",
"_id" : "320292",
"_version" : 11,
"exists" : true,
"_source" : {
"iduser":"320292",
"username":"ELDELAPAMPA",
"avatar":"userfiles/uf214/320292/avatar",
"friends":[
"43",
"51",
"54",
"55",
"66",
"69",
"285",
"893978",
"1003406",
"165",
"165"
],
"friends_qty":10
}
}
// ADDING SCRIPT
{
"script" : "ctx._source.friends += friend; ctx._source.friends_qty = ctx._source.friends.size()",
"params" : { "friend" : "???" }
}
// REMOVAL SCRIPT
{
"script" : "ctx._source.friends.remove('299'); ctx._source.friends_qty = ctx._source.friends.size()"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment