Need help constructing a query

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Need help constructing a query

Kennedy Idialu

Hi, I need help constructing a query on an index of people

 

Sample document:

 

{

     "name": "Benedict Simeon",

     "tag":  ["human", "single parent", "single"]

}

 

I need to search for people who have just the tag "single" and not "single parent", so I wrote a query

 

{

"query":

{

"query_string":

 {

"default_field": "tag",

"query": "\"single\""

}

}

}

 

The problem now is that results contain documents with tags "single parent" even if the tag "single" is not present. How do I construct my query to return only results that contain just  "single". With regex I would have expressed my query has "^single$", can I do this in elasticsearch?

 

Also, the tag field is analyzed.


Thanks

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Need help constructing a query

Rafał Kuć-3
Re: Need help constructing a query Hello!

You probably have your tag field analyzed (which is the default) behavior - in such case, the "single parent" will be broken in two tokens "single" and "parent". And that's why your query find the 'single' word even if only 'single parent' is provided. If you would like to match the exact content set the tag field to "index" : "not_analyzed" and reindexing your data. You can also try only looking for phrases (
http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html - phrase query), but I would suggest going for not analyzed field. 

-- 
Regards,
 Rafał Kuć
 Sematext :: 
http://sematext.com/ :: Solr - Lucene - Nutch - ElasticSearch


Hi, I need help constructing a query on an index of people 
 
Sample document:
 
{
     "name": "Benedict Simeon", 
     "tag":  ["human", "single parent", "single"]
}
 
I need to search for people who have just the tag "single" and not "single parent", so I wrote a query
 
{
"query": 
{
"query_string":
 {
"default_field": "tag",
"query": "\"single\""
}
}
}
 
The problem now is that results contain documents with tags "single parent" even if the tag "single" is not present. How do I construct my query to return only results that contain just  "single". With regex I would have expressed my query has "^single$", can I do this in elasticsearch?
 
Also, the tag field is analyzed.

Thanks
-- 
 
 

--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Need help constructing a query

Kennedy Idialu

I think i will go with the index: not_analyzed field. Thank you


--
 
 
Reply | Threaded
Open this post in threaded view
|

Re: Need help constructing a query

Kennedy Idialu
In reply to this post by Rafał Kuć-3

I will go with the not_analyzed field. Thank you


--