mrblue
(mrblue)
December 28, 2011, 11:25pm
1
Hi,
i have a query with 3 "and". I´d like one of them to be "OR".
So results would be for tag=green AND tag=blue AND (name= John OR name
=Dennis). Can´t figure the correct syntax..
Here is my query:
{
"query" : { "match_all" : { } } ,
"filter" : {
"and" : [
{ "term" : { "bla" : "foo" }}
{ "term" : { "foo" : "blabla" }},
{ "term" : { "color" : "blue" }}
]
},
"facets" : {
"uhren-facetten" : { "terms" : {"fields" : ["Hersteller" ,
"Ziffernblattfarbe" , "Anzeige" , "Uhrwerk" , "Armbandfarbe" ,
"Funktionen" , "Armbandmaterial" , "Wasserdichte" ], "size" :
"100" , "order" : "term" } , "all_terms" : true } }
}
NOTE: there might be a typo or two because i build the query with PHP
usually but it works fine so far
The Goal here would be to return results for color: blue OR color:
yellow as long as all results are either foo-blabla-blue or foo-blabla
yello.
Thx a lot !
Ivan
(Ivan Brusic)
December 28, 2011, 11:49pm
2
Use "must" and "should" instead of "and" and "or".
Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.
Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.
A blog post about the subject just came out when you posted:
Cheers,
Ivan
On Wed, Dec 28, 2011 at 3:25 PM, mrblue john.agricola.27@googlemail.com wrote:
Hi,
i have a query with 3 "and". I´d like one of them to be "OR".
So results would be for tag=green AND tag=blue AND (name= John OR name
=Dennis). Can´t figure the correct syntax..
Here is my query:
{
"query" : { "match_all" : { } } ,
"filter" : {
"and" : [
{ "term" : { "bla" : "foo" }}
{ "term" : { "foo" : "blabla" }},
{ "term" : { "color" : "blue" }}
]
},
"facets" : {
"uhren-facetten" : { "terms" : {"fields" : ["Hersteller" ,
"Ziffernblattfarbe" , "Anzeige" , "Uhrwerk" , "Armbandfarbe" ,
"Funktionen" , "Armbandmaterial" , "Wasserdichte" ], "size" :
"100" , "order" : "term" } , "all_terms" : true } }
}
NOTE: there might be a typo or two because i build the query with PHP
usually but it works fine so far
The Goal here would be to return results for color: blue OR color:
yellow as long as all results are either foo-blabla-blue or foo-blabla
yello.
Thx a lot !
mrblue
(mrblue)
December 29, 2011, 3:17am
3
Very interesting read and it probably fits my needs much better !
However, there is no way i can build the actual query from that doc
inside elasticsearch.. Are you willing to help me out here ?
I need a sample query for X is a must, Y is a must, A or B or C.
In this case valid results would be X-Y-A , X-Y-B , X-Y-C
(I need to dynamically add AND (=should ?) conditions to my query.
(corresponding to the facets used). Then, some will have only one
value to match, others might have up to ~12.)
I start to like this
On Dec 29, 12:49 am, Ivan Brusic i...@brusic.com wrote:
Use "must" and "should" instead of "and" and "or".
Elasticsearch Platform — Find real-time answers at scale | Elastic
A blog post about the subject just came out when you posted:Search Technology & Search Platform | Lucidworks
Cheers,
Ivan
On Wed, Dec 28, 2011 at 3:25 PM, mrblue john.agricola...@googlemail.com wrote:
Hi,
i have a query with 3 "and". I´d like one of them to be "OR".
So results would be for tag=green AND tag=blue AND (name= John OR name
=Dennis). Can´t figure the correct syntax..
Here is my query:
{
"query" : { "match_all" : { } } ,
"filter" : {
"and" : [
{ "term" : { "bla" : "foo" }}
{ "term" : { "foo" : "blabla" }},
{ "term" : { "color" : "blue" }}
]
},
"facets" : {
"uhren-facetten" : { "terms" : {"fields" : ["Hersteller" ,
"Ziffernblattfarbe" , "Anzeige" , "Uhrwerk" , "Armbandfarbe" ,
"Funktionen" , "Armbandmaterial" , "Wasserdichte" ], "size" :
"100" , "order" : "term" } , "all_terms" : true } }
}
NOTE: there might be a typo or two because i build the query with PHP
usually but it works fine so far
The Goal here would be to return results for color: blue OR color:
yellow as long as all results are either foo-blabla-blue or foo-blabla
yello.
Thx a lot !
Frederic
(Frederic)
December 29, 2011, 1:14pm
4
Hi John,
I'm not sure how to build your query using 'must'/'should' but, with
AND/OR it is pretty simple I guess:
If you want somenthing like "X and Y and (A or B or C), you may have
something like (a 'constant_score' query is equivalent to a
'match_all' one. https://groups.google.com/group/elasticsearch/browse_frm/thread/4dfdb2c2a2b30fde/26913f5863902251 ):
"query": {
"constant_score" : {
"filter" : {
"and" : [
{ "term" : { "tagX" : "X" }}
{ "term" : { "tagY" : "Y" }},
{
"or" : [
{ "term" : { "tagABC" : "A" }}
{ "term" : { "tagABC" : "B" }}
{ "term" : { "tagABC" : "C" }}
]
}
]
}
}
}
Off course I can't guarantee this is the most performant option, but
it would do the work.
Cheers,
On 29 dic, 00:17, mrblue john.agricola...@googlemail.com wrote:
Very interesting read and it probably fits my needs much better !
However, there is no way i can build the actual query from that doc
inside elasticsearch.. Are you willing to help me out here ?
I need a sample query for X is a must, Y is a must, A or B or C.
In this case valid results would be X-Y-A , X-Y-B , X-Y-C
(I need to dynamically add AND (=should ?) conditions to my query.
(corresponding to the facets used). Then, some will have only one
value to match, others might have up to ~12.)
I start to like this
On Dec 29, 12:49 am, Ivan Brusic i...@brusic.com wrote:
Use "must" and "should" instead of "and" and "or".
Elasticsearch Platform — Find real-time answers at scale | Elastic ...
A blog post about the subject just came out when you posted:Search Technology & Search Platform | Lucidworks
Cheers,
Ivan
On Wed, Dec 28, 2011 at 3:25 PM, mrblue john.agricola...@googlemail.com wrote:
Hi,
i have a query with 3 "and". I´d like one of them to be "OR".
So results would be for tag=green AND tag=blue AND (name= John OR name
=Dennis). Can´t figure the correct syntax..
Here is my query:
{
"query" : { "match_all" : { } } ,
"filter" : {
"and" : [
{ "term" : { "bla" : "foo" }}
{ "term" : { "foo" : "blabla" }},
{ "term" : { "color" : "blue" }}
]
},
"facets" : {
"uhren-facetten" : { "terms" : {"fields" : ["Hersteller" ,
"Ziffernblattfarbe" , "Anzeige" , "Uhrwerk" , "Armbandfarbe" ,
"Funktionen" , "Armbandmaterial" , "Wasserdichte" ], "size" :
"100" , "order" : "term" } , "all_terms" : true } }
}
NOTE: there might be a typo or two because i build the query with PHP
usually but it works fine so far
The Goal here would be to return results for color: blue OR color:
yellow as long as all results are either foo-blabla-blue or foo-blabla
yello.
Thx a lot !