OR query


(paul) #1

My query is as below , which gives me all the colleges with state code
"MA" i want all the colleges that are in "MA" or "NY" how to add OR filter

{
"query": {
"filtered": {
"query": {
"nested": {
"path": "programs",
"query": {
"bool": {
"must": [
{
"match": {
"programs.progName": "Computer and Information Sciences"
}
},
{
"range": {
"programs.Bachelor": {
"gt": 0
}
}
}
]
}
}
}
},
"filter": {
"and": {
"filters": [
{
"bool": {
"must": [
{
"term": {
"state": "MA"
}
},
{
"range": {
"costOutofstateTution": {
"gte": 0,
"lte": 30000
}
}
}
]
}
}
]
}
}
}
}
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9614e30f-60e8-44cc-b614-6e5c18f2bc22%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(paul) #2

I got the query wotking by using

{
"query_string": {
"default_field": "state",
"query": "MA NY"
}
}

  • Paul
    On Tuesday, 31 December 2013 11:07:06 UTC+5:30, paul wrote:

My query is as below , which gives me all the colleges with state code
"MA" i want all the colleges that are in "MA" or "NY" how to add OR filter

{
"query": {
"filtered": {
"query": {
"nested": {
"path": "programs",
"query": {
"bool": {
"must": [
{
"match": {
"programs.progName": "Computer and Information
Sciences"
}
},
{
"range": {
"programs.Bachelor": {
"gt": 0
}
}
}
]
}
}
}
},
"filter": {
"and": {
"filters": [
{
"bool": {
"must": [
{
"term": {
"state": "MA"
}
},
{
"range": {
"costOutofstateTution": {
"gte": 0,
"lte": 30000
}
}
}
]
}
}
]
}
}
}
}
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/d23102f3-3180-4cdc-9d51-8ca960c7bcd0%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Ivan Brusic) #3

You are better of using a proper boolean filter for better performance.
Queries cannot be cached and query string query analyzes the terms. Here is
an example of your filter with a nested bool (should) filter:

"filter": {
"and": {
"filters": [
{
"bool": {
"must": [
{
"bool": {
"should": [
{
"term": {
"state": "MA"
}
},
{
"term": {
"state": "NY"
}
}
]
}
},
{
"range": {
"costOutofstateTution": {
"gte": 0,
"lte": 30000
}
}
}
]
}
}
]
}
}

Cheers,

Ivan

On Mon, Dec 30, 2013 at 10:03 PM, paul avinashpaul85@gmail.com wrote:

I got the query wotking by using

{
"query_string": {
"default_field": "state",
"query": "MA NY"
}
}

  • Paul

On Tuesday, 31 December 2013 11:07:06 UTC+5:30, paul wrote:

My query is as below , which gives me all the colleges with state code
"MA" i want all the colleges that are in "MA" or "NY" how to add OR filter

{
"query": {
"filtered": {
"query": {
"nested": {
"path": "programs",
"query": {
"bool": {
"must": [
{
"match": {
"programs.progName": "Computer and Information
Sciences"
}
},
{
"range": {
"programs.Bachelor": {
"gt": 0
}
}
}
]
}
}
}
},
"filter": {
"and": {
"filters": [
{
"bool": {
"must": [
{
"term": {
"state": "MA"
}
},
{
"range": {
"costOutofstateTution": {
"gte": 0,
"lte": 30000
}
}
}
]
}
}
]
}
}
}
}
}

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/d23102f3-3180-4cdc-9d51-8ca960c7bcd0%40googlegroups.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQC5FF-F%3DLJzpsVUvcq1n%2B%2B_9DFcKgRFJ0r%3Dv3SS7jX_tQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(paul) #4

Thank you Ivan will definitely try it out.

-paul

On Tue, Dec 31, 2013 at 10:51 PM, Ivan Brusic ivan@brusic.com wrote:

You are better of using a proper boolean filter for better performance.
Queries cannot be cached and query string query analyzes the terms. Here is
an example of your filter with a nested bool (should) filter:

"filter": {
"and": {
"filters": [
{
"bool": {
"must": [
{
"bool": {
"should": [
{
"term": {
"state": "MA"
}
},
{
"term": {
"state": "NY"
}
}
]
}
},
{
"range": {
"costOutofstateTution": {
"gte": 0,
"lte": 30000
}
}
}
]
}
}
]
}
}

Cheers,

Ivan

On Mon, Dec 30, 2013 at 10:03 PM, paul avinashpaul85@gmail.com wrote:

I got the query wotking by using

{
"query_string": {
"default_field": "state",
"query": "MA NY"
}
}

  • Paul

On Tuesday, 31 December 2013 11:07:06 UTC+5:30, paul wrote:

My query is as below , which gives me all the colleges with state code
"MA" i want all the colleges that are in "MA" or "NY" how to add OR filter

{
"query": {
"filtered": {
"query": {
"nested": {
"path": "programs",
"query": {
"bool": {
"must": [
{
"match": {
"programs.progName": "Computer and Information
Sciences"
}
},
{
"range": {
"programs.Bachelor": {
"gt": 0
}
}
}
]
}
}
}
},
"filter": {
"and": {
"filters": [
{
"bool": {
"must": [
{
"term": {
"state": "MA"
}
},
{
"range": {
"costOutofstateTution": {
"gte": 0,
"lte": 30000
}
}
}
]
}
}
]
}
}
}
}
}

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/d23102f3-3180-4cdc-9d51-8ca960c7bcd0%40googlegroups.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/rd6Lh_U0lzI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQC5FF-F%3DLJzpsVUvcq1n%2B%2B_9DFcKgRFJ0r%3Dv3SS7jX_tQ%40mail.gmail.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAO066G0Ng7dhg3U8L%3Dc49%2BDkM_xWP5feXNYN%3Dfa6Nx55oqSn%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #5