Nested Query & Filter Query

Hi Elastic Searchers,

I am completely new to Elasticsearch but have been progressing well this
week, I'm just hoping one of you may be able to help nudge me over the
final hurdle.

I have a complete gist here that populates an index with 2 rock bands and
their members and runs a successful nested search query to find bands
containing members with the name Roger (2 results).

However, what I also need is to be able to filter the results by other
attributes, such as the year the band formed, or perhaps part of the band's
name, 'Pink' for example. 1 or more additional filters.

I have been through the documentation and tried at least a dozen different
JSON structures to try to get that final search to filter by year or band
name in addition to the nested query, but without success :confused:

Everything I have tried so far has either returned no results at all or has
just produced an error and failed entirely.

Can someone please help advise.

Cheers for any help.

--
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/a61b1bed-d4cf-4ad2-8234-fc37d53190c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Here is an example based on your data: https://gist.github.com/dadoonet/64458f7423863d93c49e

HTH

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

Le 16 juillet 2014 à 12:58:40, Dark Globe (glen@henleydev.co.uk) a écrit:

Hi Elastic Searchers,

I am completely new to Elasticsearch but have been progressing well this week, I'm just hoping one of you may be able to help nudge me over the final hurdle.

I have a complete gist here that populates an index with 2 rock bands and their members and runs a successful nested search query to find bands containing members with the name Roger (2 results).

However, what I also need is to be able to filter the results by other attributes, such as the year the band formed, or perhaps part of the band's name, 'Pink' for example. 1 or more additional filters.

I have been through the documentation and tried at least a dozen different JSON structures to try to get that final search to filter by year or band name in addition to the nested query, but without success :confused:

Everything I have tried so far has either returned no results at all or has just produced an error and failed entirely.

Can someone please help advise.

Cheers for any help.

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/a61b1bed-d4cf-4ad2-8234-fc37d53190c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/etPan.53c6648c.6b8b4567.86d7%40MacBook-Air-de-David.local.
For more options, visit https://groups.google.com/d/optout.

Wow!, Thanks so much David.

--
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/b93f3370-3b52-456d-a828-1f612f1bb354%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi again,

Sorry, I've been looking through the
documentation: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html
to try to work out how to supply multiple filters.

Once again though I am struggling to work out how to build the array as
I've tried several different approaches but all result in an error,
including my latest effort which you can see in my original gist which I
have now updated to include your successful filter and my subsequent
failure.

Clearly there is something fundamental about how these JSON objects are
structured that I simply don't understand. What am I missing?

Thanks again for any help.

--
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/2dc68147-79a5-4281-987d-a81f3bda3839%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Just found that replacing "match" for "term" in my second filter condition
runs without error...but doesn't actually work so no results are returned
when 1 should be :confused:

I'm sure I'm getting closer and I'm sure I shouldn't be finding this such a
struggle!

Any pointers are welcome and appreciated.

--
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/f706abeb-461f-49e7-8f15-5cf6bf86cc0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Match only exists as a query.
Term exists as a filter and as a query.

Think about queries as full text search. Filters are like SQL. They "only" limit the dataset your are going to query on.

You should read Elasticsearch Platform — Find real-time answers at scale | Elastic

HTH

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 16 juil. 2014 à 16:07, Dark Globe glen@henleydev.co.uk a écrit :

Just found that replacing "match" for "term" in my second filter condition runs without error...but doesn't actually work so no results are returned when 1 should be :confused:

I'm sure I'm getting closer and I'm sure I shouldn't be finding this such a struggle!

Any pointers are welcome and appreciated.

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/f706abeb-461f-49e7-8f15-5cf6bf86cc0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/D566800F-B75E-4F9C-BD38-C400FC11D81A%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

Thanks David, I did read that section a couple of days back and again just
now but I still don't understand why the final search in my gist does not
return one result.

If I remove { "term": { "title" : "Floyd" }} and run the script, the final
search returns one result, Pink Floyd.

But I think it should also return that same result with the term filter { "term":
{ "title" : "Floyd" }} added. But it doesn't.

I still do not understand why this is or what I am doing wrong :confused:

--
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/20ead9ad-bead-497f-b0f1-6786e9fc8ab0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Floyd needs to be lowercased if you use a Term Filter or query

As it has been indexed in lowercase.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 16 juil. 2014 à 18:09, Dark Globe glen@henleydev.co.uk a écrit :

Thanks David, I did read that section a couple of days back and again just now but I still don't understand why the final search in my gist does not return one result.

If I remove { "term": { "title" : "Floyd" }} and run the script, the final search returns one result, Pink Floyd.

But I think it should also return that same result with the term filter { "term": { "title" : "Floyd" }} added. But it doesn't.

I still do not understand why this is or what I am doing wrong :confused:

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/20ead9ad-bead-497f-b0f1-6786e9fc8ab0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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/2EB2635B-5B67-4B9C-8650-31AF29B43DEC%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.

YES!

Thank you so much David. I've been pulling my hair out trying different
structures when it was that little gotcha all along grrr!

I wil take some comfort, however, in the fact that I had actually got the
structure right this time.

Thank you so much David for all your help - thanks to you, I will be able
to demonstrate ElasticSearch as a viable solution tomorrow.

--
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/295c6fbe-1904-41c0-ab17-b24a47d4694d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.