Exact match on an array field


(marrese@gmail.com) #1

Guys,

Hi, I have a document with many fields, and one of them is an array (a
topics array). Currently that array has only one entry per document but in
the future we'll have more entries. The thing is that I can't make an exact
query on the topic array field when looking for more than one term in it.

Let say the documents stored have one of the following values on that
field: Martin, Martin Ariel, Ariel, Kyheo
So a doc will look something like this:

{
'text': 'some random text',
'date': '2011-12-12T15:17:35.000Z'.
'topics': ['Martin']
}

I'm doing this query (1) and the problem is that all the docs with Kyheoor
Martin or Martin Ariel in the topic field are returned, but I only want
those having Kyheo or Martin. I'm stuck, looked in the docs but got
confused. Any help please ?

Thanks,
Martin

Links:
1- https://gist.github.com/1473724

--
Martín

http://www.kyheo.com.ar
GTalk: marrese@gmail.com


(Shay Banon) #2

Make the field as not_analyzed, then it will be exact match. Though, in
your case, you are testing for lowercase value, so if you want to ignore
casing, you will need to create a custom analyzed with a keyword tokenized
and a lowercase filter, and then associate it with the topics field in your
mapping.

On Tue, Dec 13, 2011 at 10:52 PM, marrese@gmail.com marrese@gmail.comwrote:

Guys,

Hi, I have a document with many fields, and one of them is an array (a
topics array). Currently that array has only one entry per document but in
the future we'll have more entries. The thing is that I can't make an exact
query on the topic array field when looking for more than one term in it.

Let say the documents stored have one of the following values on that
field: Martin, Martin Ariel, Ariel, Kyheo
So a doc will look something like this:

{
'text': 'some random text',
'date': '2011-12-12T15:17:35.000Z'.
'topics': ['Martin']
}

I'm doing this query (1) and the problem is that all the docs with Kyheoor
Martin or Martin Ariel in the topic field are returned, but I only
want those having Kyheo or Martin. I'm stuck, looked in the docs but
got confused. Any help please ?

Thanks,
Martin

Links:
1- https://gist.github.com/1473724

--
Martín

http://www.kyheo.com.ar
GTalk: marrese@gmail.com


(system) #3