Returning (at least) one of each filter

Given I have an index that has documents of flights with fields for origin
and destination airports, how can I construct a query that given a single
origin and a list of destinations, I will get at least 1 of each
origin-destination pairing?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Do you have one instance of origin-destination airports or many of them in a single doc?
If you have many of them, you should first consider to use nested docs.

That said, you can build a BoolFilter [2] with the first must clause with a TermFilter [3] on origin and the second must clause with a TermsFilter [1] on destination.

HTH

[1] http://www.elasticsearch.org/guide/reference/query-dsl/terms-filter/
[2] http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter/
[3] http://www.elasticsearch.org/guide/reference/query-dsl/term-filter/

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 4 avr. 2013 à 07:08, Akhil Patel akhil.patel@gmail.com a écrit :

Given I have an index that has documents of flights with fields for origin and destination airports, how can I construct a query that given a single origin and a list of destinations, I will get at least 1 of each origin-destination pairing?

--
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.
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.
For more options, visit https://groups.google.com/groups/opt_out.

Right, so the index could have 13 docs like this:

SEA LHR 1
SEA LHR 2
SEA DFW 1
SEA LAX 1
SEA SFO 1
SFO YVR 1
TPE BKK 1
SEA SYD 1
LAS JFK 1
SEA DFW 2
SEA EDI 1
AMS DAR 1
SEA BOM 1

And I provide it SEA as the origin airport and LAX,LHR and BOM as
destinations. The documents I'd like returned are:

SEA-LHR 1
SEA-LHR 2
SEA-LAX 1
SEA-BOM 1

Is that still possible using the method you described above, and what would
it look like?

On Thursday, April 4, 2013 12:23:03 AM UTC-7, David Pilato wrote:

Do you have one instance of origin-destination airports or many of them in
a single doc?
If you have many of them, you should first consider to use nested docs.

That said, you can build a BoolFilter [2] with the first must clause with
a TermFilter [3] on origin and the second must clause with a
TermsFilter [1] on destination.

HTH

[1] http://www.elasticsearch.org/guide/reference/query-dsl/terms-filter/
[2] http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter/
[3] http://www.elasticsearch.org/guide/reference/query-dsl/term-filter/

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
| @scrutmydocs https://twitter.com/scrutmydocs

Le 4 avr. 2013 à 07:08, Akhil Patel <akhil...@gmail.com <javascript:>> a
écrit :

Given I have an index that has documents of flights with fields for origin
and destination airports, how can I construct a query that given a single
origin and a list of destinations, I will get at least 1 of each
origin-destination pairing?

--
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 elasticsearc...@googlegroups.com <javascript:>.
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.
For more options, visit https://groups.google.com/groups/opt_out.

I guess I should also clarify; if there are > 10,000 documents, I'd like to
restrict my query to returning me 100 that guarantees I have something that
matches each thing in my terms filter.

On Thursday, April 4, 2013 6:57:08 AM UTC-7, Akhil Patel wrote:

Right, so the index could have 13 docs like this:

SEA LHR 1
SEA LHR 2
SEA DFW 1
SEA LAX 1
SEA SFO 1
SFO YVR 1
TPE BKK 1
SEA SYD 1
LAS JFK 1
SEA DFW 2
SEA EDI 1
AMS DAR 1
SEA BOM 1

And I provide it SEA as the origin airport and LAX,LHR and BOM as
destinations. The documents I'd like returned are:

SEA-LHR 1
SEA-LHR 2
SEA-LAX 1
SEA-BOM 1

Is that still possible using the method you described above, and what
would it look like?

On Thursday, April 4, 2013 12:23:03 AM UTC-7, David Pilato wrote:

Do you have one instance of origin-destination airports or many of them
in a single doc?
If you have many of them, you should first consider to use nested docs.

That said, you can build a BoolFilter [2] with the first must clause with
a TermFilter [3] on origin and the second must clause with a
TermsFilter [1] on destination.

HTH

[1] http://www.elasticsearch.org/guide/reference/query-dsl/terms-filter/
[2] http://www.elasticsearch.org/guide/reference/query-dsl/bool-filter/
[3] http://www.elasticsearch.org/guide/reference/query-dsl/term-filter/

--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet https://twitter.com/dadoonet | @elasticsearchfrhttps://twitter.com/elasticsearchfr
| @scrutmydocs https://twitter.com/scrutmydocs

Le 4 avr. 2013 à 07:08, Akhil Patel akhil...@gmail.com a écrit :

Given I have an index that has documents of flights with fields for
origin and destination airports, how can I construct a query that given a
single origin and a list of destinations, I will get at least 1 of each
origin-destination pairing?

--
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 elasticsearc...@googlegroups.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.
For more options, visit https://groups.google.com/groups/opt_out.