Exact match a string


(coys) #1

Hello, I would like to perform an exact match on a string - say for
e.g. the field status which is an enum - taking 2 values
["Automated","To be Automated"].

When I query for status:"To be automated" I require that it return
only those results where status is exactly "To be Automated" and not
"Automated" and if I query for status:"Automated" I again require that
it does not return to me the results where status is "To be
Automated".

I read a previous question where it was suggested that I set index to
not_analyzed or keyword for the above field, but is there a way for me
to get these results without doing the above..and just with the help
of a query? Thanks!


(Shaun Farrell) #2

You can but I'm not sure it will be as performat to do it.

You can try a field query where its like

+automated -to -be

and see if that works. The problem is that you are using the default mapping i assume and its going to tokenize those strings.

Thanks,

Shaun Farrell

On Thursday, July 5, 2012 at 1:49 PM, coys wrote:

Hello, I would like to perform an exact match on a string - say for
e.g. the field status which is an enum - taking 2 values
["Automated","To be Automated"].

When I query for status:"To be automated" I require that it return
only those results where status is exactly "To be Automated" and not
"Automated" and if I query for status:"Automated" I again require that
it does not return to me the results where status is "To be
Automated".

I read a previous question where it was suggested that I set index to
not_analyzed or keyword for the above field, but is there a way for me
to get these results without doing the above..and just with the help
of a query? Thanks!


(David Pilato) #3

With default analyzer, i'm afraid you will never find "to" and "be" as they are english common words. So -to -be won't have any effect.

My 2 cents.

David

--

Le 5 juil. 2012 à 19:58, Shaun Farrell farrelley@gmail.com a écrit :

You can but I'm not sure it will be as performat to do it.

You can try a field query where its like

+automated -to -be

and see if that works. The problem is that you are using the default mapping i assume and its going to tokenize those strings.

Thanks,

Shaun Farrell

On Thursday, July 5, 2012 at 1:49 PM, coys wrote:

Hello, I would like to perform an exact match on a string - say for
e.g. the field status which is an enum - taking 2 values
["Automated","To be Automated"].

When I query for status:"To be automated" I require that it return
only those results where status is exactly "To be Automated" and not
"Automated" and if I query for status:"Automated" I again require that
it does not return to me the results where status is "To be
Automated".

I read a previous question where it was suggested that I set index to
not_analyzed or keyword for the above field, but is there a way for me
to get these results without doing the above..and just with the help
of a query? Thanks!


(coys) #4

Yep David, you're right, looks I can't find those common words, so I
guess I'll just go ahead and index that field as not_analyzed. Thanks
a lot for the replies guys!


(coys) #5

curl -XPUT 'http://localhost:9200/nameofindex/nameofmapping/_mapping'
-d '

{
"typeofindex" : {
"properties" : {
"metadata.status" : {"type" : "string", "index" : "not_analyzed"}
}
}
}
Just to update, I created this mapping and this worked for me. After
creating this mapping I can now differentiate between fields whose
status are Automated and To be Automated.


(aps) #6

Are you getting documents when you search "auto" ? Because the problem with
not_analyzed is it do not search documents with matching type if few of the
words is provided in search query.

On Friday, 6 July 2012 00:11:25 UTC+2, coys wrote:

curl -XPUT 'http://localhost:9200/nameofindex/nameofmapping/_mapping'
-d '

{
"typeofindex" : {
"properties" : {
"metadata.status" : {"type" : "string", "index" : "not_analyzed"}
}
}
}
Just to update, I created this mapping and this worked for me. After
creating this mapping I can now differentiate between fields whose
status are Automated and To be Automated.


(coys) #7

I'll add in what I quickly tested..I have 2 docs..1 which has status
"To be Automated" and 2 which has status "Automated"..search results
are as follows - in my textbox if I type "To" or "To be" or "To be
Automated" it returns 1 correctly..however if I type "Auto" or
"Automated" it only returns doc 2 and does not return doc1..however, I
only provide a comboxbox so I'm able to return the required doc
according to status correctly. Thanks


(system) #8