Adding / Removing entries from an array

Hi there.
It's my first time with ES so sorry if I make a dumb question.

*Question: *
I'm trying to remove an object from an array.

Why?:
We plan to use ES like some sort of DB for fast retrieval, instead of
hitting MySQL.
Our RDBMS we'll keep being our datastore.

Background:
The project I'm in is a social network so I'm planning to use ES to store
via API "user" objects for fast store and retrieval (today MySQL is nor
performing very well)
We'll be doing around 350 GET reqs/sec and around 150 POST()insert/updates)
reqs/sec.

The proposed user object structure is like this:
{

  • "_index":"session",
  • "_type":"user",
  • "_id":"320292",
  • "_version":4,
  • "exists":true,
  • "_source":{
    • "iduser":320292,
    • "username":"FAKEPROFILE",
    • "avatar":"userfiles/uf214/320292/avatar",
    • "friends":[
      • 43,
      • 51,
      • 54,
      • 55,
      • 66,
      • 69,
      • 285,
      • 893978,
      • 1003406,
      • 666
        ],
    • "friends_qty":9
      }

}

I've successfully added USER ID 666 with the syntax at Docs page:
{
"script" : "ctx._source.friends += friend",
"params" : {
"friend" : 666
}
}

Problem is that I tried "script" : "ctx._source.friends -= friend" without
success.

I'm trying to update record in place since some users have a very long list
of friends that could become about 16Mb-length string.
I plan to populate once, then keep updated.

If any of you have also any input/advice on any other topic of the proposed
idea don't hesitate to add it.

Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,

I think you have to use some of the [1]Projects and Folds of MVEL (the
default scripting language). I did some time ago but I did not remember
exactly, sorry

[1] - http://mvel.codehaus.org/MVEL+2.0+Projections+and+Folds

On Mon, Mar 4, 2013 at 7:20 PM, Fernando Javier Martin <
fernandojmartin@gmail.com> wrote:

Hi there.
It's my first time with ES so sorry if I make a dumb question.

*Question: *
I'm trying to remove an object from an array.

Why?:
We plan to use ES like some sort of DB for fast retrieval, instead of
hitting MySQL.
Our RDBMS we'll keep being our datastore.

Background:
The project I'm in is a social network so I'm planning to use ES to store
via API "user" objects for fast store and retrieval (today MySQL is nor
performing very well)
We'll be doing around 350 GET reqs/sec and around 150
POST()insert/updates) reqs/sec.

The proposed user object structure is like this:
{

  • "_index":"session",
  • "_type":"user",
  • "_id":"320292",
  • "_version":4,
  • "exists":true,
  • "_source":{
    • "iduser":320292,
    • "username":"FAKEPROFILE",
    • "avatar":"userfiles/uf214/320292/avatar",
    • "friends":[
      • 43,
      • 51,
      • 54,
      • 55,
      • 66,
      • 69,
      • 285,
      • 893978,
      • 1003406,
      • 666
        ],
    • "friends_qty":9
      }

}

I've successfully added USER ID 666 with the syntax at Docs page:
{
"script" : "ctx._source.friends += friend",
"params" : {
"friend" : 666
}
}

Problem is that I tried "script" : "ctx._source.friends -= friend" without
success.

I'm trying to update record in place since some users have a very long
list of friends that could become about 16Mb-length string.
I plan to populate once, then keep updated.

If any of you have also any input/advice on any other topic of the
proposed idea don't hesitate to add it.

Thanks in advance!

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Paco Guzmán
e-mail: pacoguzmanp@gmail.com
blog: pacoguzman.lacoctelera.net/

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks Paco!

I've dived into MVEL docs and found this syntax to work:

// Adding
{
"script" : "ctx._source.friends += friend; ctx._source.friends_qty += 1",
"params" : { "friend" : "299" }
}

// Removing
{
"script" : "ctx._source.friends.remove("199"); ctx._source.friends_qty -=
1"
}

However decreasing the counter in this way doesn't works (this may be my
next question).
I was unable to get the property size() too.
Anyway, I've managed to add/remove elements from a List.

Thanks!

El lunes, 4 de marzo de 2013 15:50:45 UTC-3, Paco Guzmán escribió:

Hi,

I think you have to use some of the [1]Projects and Folds of MVEL (the
default scripting language). I did some time ago but I did not remember
exactly, sorry

[1] - http://mvel.codehaus.org/MVEL+2.0+Projections+and+Folds

On Mon, Mar 4, 2013 at 7:20 PM, Fernando Javier Martin <
fernand...@gmail.com <javascript:>> wrote:

Hi there.
It's my first time with ES so sorry if I make a dumb question.

*Question: *
I'm trying to remove an object from an array.

Why?:
We plan to use ES like some sort of DB for fast retrieval, instead of
hitting MySQL.
Our RDBMS we'll keep being our datastore.

Background:
The project I'm in is a social network so I'm planning to use ES to store
via API "user" objects for fast store and retrieval (today MySQL is nor
performing very well)
We'll be doing around 350 GET reqs/sec and around 150
POST()insert/updates) reqs/sec.

The proposed user object structure is like this:
{

  • "_index":"session",
  • "_type":"user",
  • "_id":"320292",
  • "_version":4,
  • "exists":true,
  • "_source":{
    • "iduser":320292,
    • "username":"FAKEPROFILE",
    • "avatar":"userfiles/uf214/320292/avatar",
    • "friends":[
      • 43,
      • 51,
      • 54,
      • 55,
      • 66,
      • 69,
      • 285,
      • 893978,
      • 1003406,
      • 666
        ],
    • "friends_qty":9
      }

}

I've successfully added USER ID 666 with the syntax at Docs page:
{
"script" : "ctx._source.friends += friend",
"params" : {
"friend" : 666
}
}

Problem is that I tried "script" : "ctx._source.friends -= friend" without
success.

I'm trying to update record in place since some users have a very long
list of friends that could become about 16Mb-length string.
I plan to populate once, then keep updated.

If any of you have also any input/advice on any other topic of the
proposed idea don't hesitate to add it.

Thanks in advance!

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
Paco Guzmán
e-mail: pacog...@gmail.com <javascript:>
blog: pacoguzman.lacoctelera.net/

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.