Elastic Query String Query Search

I am trying to get records using Query String Query .
My search script is as follows:
I need to search for: "I Love my " AND (HTC OR Iphone OR Samsung)
And I expect a result like:

  • I love my HTC
  • I love my iphone.
  • I love my Samsung.

I just tried a few combinations but didn't work

 { "query": { "query_string": { "default_field": "SearchContent", "query": "\"I Love my\" AND (HTC OR Iphone OR Samsung)" } } } 

How can I do this with a Query String? Or is there another option, I'm stuck. Help me.

+4
source share
4 answers

The request depends on your _mapping. If you did not define it, then probably a standard analyzer is used. If so, then the tokens:

  • I love my HTC โ†’ "i", "love", "my", "htc"
  • I love my Iphone โ†’ "i", "love", "my", "iphone"
  • I love my Samsung โ†’ "i", "love", "my", "samsung".

Note that markers are lowercase.

The correct query string format is:

 GET /yourindex/_search { "query": { "query_string": { "default_field": "SearchContent", "query": "\"i love my\" AND (samsung OR htc OR iphone)" } } } 
+9
source

Well yes. You can create filtered quesry based on match_all query with filters that interest you, combine and / or filter. Here you want to return documents containing one of three phrases. I guess you donโ€™t want โ€œI like my cake and I have an iphoneโ€ to return.

So, something like this (I donโ€™t know if this is enough, tough).

 { "filtered" : { "query" : { "match_all" : {} }, "filter" : { "or" : { "filters" : [{ "fquery" : { "query" : { "query_string" : { "query" : "\"I love my iphone\"", "default_field" : "searchContent", "default_operator" : "and" } } } },{ "fquery" : { "query" : { "query_string" : { "query" : "\"I love my htc\"", "default_field" : "searchContent", "default_operator" : "and" } } } }, { "fquery" : { "query" : { "query_string" : { "query" : "\"I love my samsung\"", "default_field" : "searchContent", "default_operator" : "and" } } } } ] } } } 

}

0
source

Try it...

 { "query": { "query_string": { "default_field": "SearchContent", "query": "I Love my *" } } } 

A wild card does not scale well if the data is too large. But it can help if performance is not a major issue (less data).

0
source

You can use the query string below to search for the same.

 { "query_string" : { "fields" : ["content", "my_field"], "query" : "\"I love my \" HTC Iphone Samsung" } } 

Try it, it will help you. or check: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

-2
source

Source: https://habr.com/ru/post/1499322/


All Articles