Searching in arrays

Hello,

I'm indexing documents that contains arrays, for example:

{
"record" :
{
"properties" :
{
"someId" : {"type" : "integer"},
"categories" :
{
"properties" :
{
"cId" : {"type" : "integer"},
"cScore" : {"type" : "integer"}
}
}
}
}
}

I would like to search for categories that their id AND score matching
some values. My problem is that the results contain categories that
either their cId or cScore matches the criteria. This is the query I
used:

curl -XGET 'http://localhost:9200/index/record/_search?
q=categories.cId:70&categories.sScore:25'

Is there some other syntax I should use, or should I filter the
results in the app?

Thanks.

This is how the search work. One way to solve this is to have a document per "array instance", then you can do this join.
On Tuesday, January 18, 2011 at 2:48 PM, barak wrote:

Hello,

I'm indexing documents that contains arrays, for example:

{
"record" :
{
"properties" :
{
"someId" : {"type" : "integer"},
"categories" :
{
"properties" :
{
"cId" : {"type" : "integer"},
"cScore" : {"type" : "integer"}
}
}
}
}
}

I would like to search for categories that their id AND score matching
some values. My problem is that the results contain categories that
either their cId or cScore matches the criteria. This is the query I
used:

curl -XGET 'http://localhost:9200/index/record/_search?
q=categories.cId:70&categories.sScore:25'

Is there some other syntax I should use, or should I filter the
results in the app?

Thanks.

Can you explain the "document per array instance"? Should the array be
key?..

I'll be glad if you can an example...

Thanks!

On Jan 18, 8:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

This is how the search work. One way to solve this is to have a document per "array instance", then you can do this join.

On Tuesday, January 18, 2011 at 2:48 PM, barak wrote:

Hello,

I'm indexing documents that contains arrays, for example:

{
"record" :
{
"properties" :
{
"someId" : {"type" : "integer"},
"categories" :
{
"properties" :
{
"cId" : {"type" : "integer"},
"cScore" : {"type" : "integer"}
}
}
}
}
}

I would like to search for categories that their id AND score matching
some values. My problem is that the results contain categories that
either their cId or cScore matches the criteria. This is the query I
used:

curl -XGET 'http://localhost:9200/index/record/_search?
q=categories.cId:70&categories.sScore:25'

Is there some other syntax I should use, or should I filter the
results in the app?

Thanks.

I mean that each index document will be an element in the array. For example, you will have a recover_property as a document, and not a record.
On Tuesday, January 18, 2011 at 8:52 PM, barak wrote:

Can you explain the "document per array instance"? Should the array be
key?..

I'll be glad if you can an example...

Thanks!

On Jan 18, 8:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

This is how the search work. One way to solve this is to have a document per "array instance", then you can do this join.

On Tuesday, January 18, 2011 at 2:48 PM, barak wrote:

Hello,

I'm indexing documents that contains arrays, for example:

{
"record" :
{
"properties" :
{
"someId" : {"type" : "integer"},
"categories" :
{
"properties" :
{
"cId" : {"type" : "integer"},
"cScore" : {"type" : "integer"}
}
}
}
}
}

I would like to search for categories that their id AND score matching
some values. My problem is that the results contain categories that
either their cId or cScore matches the criteria. This is the query I
used:

curl -XGET 'http://localhost:9200/index/record/_search?
q=categories.cId:70&categories.sScore:25'

Is there some other syntax I should use, or should I filter the
results in the app?

Thanks.

I think I lost you... For the mapping above, can you please guide me
how to rephrase it to support the type of search I'm trying to do?

Thanks!

On Jan 19, 12:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

I mean that each index document will be an element in the array. For example, you will have a recover_property as a document, and not a record.

On Tuesday, January 18, 2011 at 8:52 PM, barak wrote:

Can you explain the "document per array instance"? Should the array be
key?..

I'll be glad if you can an example...

Thanks!

On Jan 18, 8:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

This is how the search work. One way to solve this is to have a document per "array instance", then you can do this join.

On Tuesday, January 18, 2011 at 2:48 PM, barak wrote:

Hello,

I'm indexing documents that contains arrays, for example:

{
"record" :
{
"properties" :
{
"someId" : {"type" : "integer"},
"categories" :
{
"properties" :
{
"cId" : {"type" : "integer"},
"cScore" : {"type" : "integer"}
}
}
}
}
}

I would like to search for categories that their id AND score matching
some values. My problem is that the results contain categories that
either their cId or cScore matches the criteria. This is the query I
used:

curl -XGET 'http://localhost:9200/index/record/_search?
q=categories.cId:70&categories.sScore:25'

Is there some other syntax I should use, or should I filter the
results in the app?

Thanks.

I'm still trying to solve this issue, can anyone help with an example?
I googled for it, but I can't find something helpful..

Thanks.

On Jan 19, 3:07 pm, barak barak.ya...@gmail.com wrote:

I think I lost you... For the mapping above, can you please guide me
how to rephrase it to support the type of search I'm trying to do?

Thanks!

On Jan 19, 12:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

I mean that each index document will be an element in the array. For example, you will have a recover_property as a document, and not a record.

On Tuesday, January 18, 2011 at 8:52 PM, barak wrote:

Can you explain the "document per array instance"? Should the array be
key?..

I'll be glad if you can an example...

Thanks!

On Jan 18, 8:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

This is how the search work. One way to solve this is to have a document per "array instance", then you can do this join.

On Tuesday, January 18, 2011 at 2:48 PM, barak wrote:

Hello,

I'm indexing documents that contains arrays, for example:

{
"record" :
{
"properties" :
{
"someId" : {"type" : "integer"},
"categories" :
{
"properties" :
{
"cId" : {"type" : "integer"},
"cScore" : {"type" : "integer"}
}
}
}
}
}

I would like to search for categories that their id AND score matching
some values. My problem is that the results contain categories that
either their cId or cScore matches the criteria. This is the query I
used:

curl -XGET 'http://localhost:9200/index/record/_search?
q=categories.cId:70&categories.sScore:25'

Is there some other syntax I should use, or should I filter the
results in the app?

Thanks.

Lets say you index a document, and it has an array of two fields, field1, and field2, then you run into the problem mentioned in the first mail, where doing field1 AND field2 might return hits where the field1 value exists in one array element, and field2 exists in another.

A way to solve this is to index each array element as a different document. A single document that consists of a single value of field1 and a single value of field2.

-shay.banon

On Thursday, January 20, 2011 at 4:14 PM, barak wrote:

I'm still trying to solve this issue, can anyone help with an example?
I googled for it, but I can't find something helpful..

Thanks.

On Jan 19, 3:07 pm, barak barak.ya...@gmail.com wrote:

I think I lost you... For the mapping above, can you please guide me
how to rephrase it to support the type of search I'm trying to do?

Thanks!

On Jan 19, 12:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

I mean that each index document will be an element in the array. For example, you will have a recover_property as a document, and not a record.

On Tuesday, January 18, 2011 at 8:52 PM, barak wrote:

Can you explain the "document per array instance"? Should the array be
key?..

I'll be glad if you can an example...

Thanks!

On Jan 18, 8:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

This is how the search work. One way to solve this is to have a document per "array instance", then you can do this join.

On Tuesday, January 18, 2011 at 2:48 PM, barak wrote:

Hello,

I'm indexing documents that contains arrays, for example:

{
"record" :
{
"properties" :
{
"someId" : {"type" : "integer"},
"categories" :
{
"properties" :
{
"cId" : {"type" : "integer"},
"cScore" : {"type" : "integer"}
}
}
}
}
}

I would like to search for categories that their id AND score matching
some values. My problem is that the results contain categories that
either their cId or cScore matches the criteria. This is the query I
used:

curl -XGET 'http://localhost:9200/index/record/_search?
q=categories.cId:70&categories.sScore:25'

Is there some other syntax I should use, or should I filter the
results in the app?

Thanks.