Re: Using NOT in a nested filter

2014-01-09 Thread Nathan Moon
Oh right.  That should have been obvious.  It seems to be working great that 
way.  Thanks!

Nathan

On Jan 9, 2014, at 1:10 PM, Sloan Ahrens sl...@stacksearch.com wrote:

 You were close. You just had the nested and not filters in the wrong
 order, basically. 
 
 Your (first) query says return items that have a rating with
 'ratings.rater_username' not equal to 'user1'. And so you get the first
 item, since it meets that requirement. 
 
 What you really want to say is return items for which all ratings have
 'ratings.rater_username' not equal to 'user1'. Here is the query you want:
 
 curl -XPOST http://localhost:9200/nestedfilters/item/_search; -d'
 {
   query: {
  match_all: {}
   },
   filter: {
  not: {
 nested: {
path: ratings,
filter: {
   term: {
  ratings.rater_username: user1
   }
}
 }
  }
   }
 }'
 
 Here is a runnable example you can play with (you will need ES installed and
 running at localhost:9200, or supply another endpoint):
 http://sense.qbox.io/gist/289ceb80480db8b6574d5f879358e50c97aaf5da
 
 
 
 
 -
 Co-Founder and CTO, StackSearch, Inc. 
 Hosted Elasticsearch at http://qbox.io
 --
 View this message in context: 
 http://elasticsearch-users.115913.n3.nabble.com/Using-NOT-in-a-nested-filter-tp4047349p4047353.html
 Sent from the ElasticSearch Users mailing list archive at Nabble.com.
 
 -- 
 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/7yWbMCYmAFw/unsubscribe.
 To unsubscribe from this group and all its topics, send an email to 
 elasticsearch+unsubscr...@googlegroups.com.
 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/elasticsearch/1389298238074-4047353.post%40n3.nabble.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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/128FBB57-B971-4D1C-A3A6-E4F5A3F2BC3D%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


facets on nested objects, plus facet_filter

2014-01-02 Thread Nathan Moon
Hi, I am using nested objects for indexing “ratings” on an object, where a 
rating contains two properties: the owner and the rating.  I want to be able to 
filter and facet on “my ratings”.  So to filter, for example, on objects I have 
rated a “10, I am using a filter like 

{ 
“nested” : { 
“path” : “ratings”,
“filter” : {
“and” : [{
“term” { “ratings.rating” : 10 },
“term” { “ratings.owner” : “my_id” }
}]
}
}
}

I also want to facet on “my rating”, which in a basic form I’m doing like this:

“facets” : {
“my_ratings” : {
“nested” : “ratings”,
“terms” : {
“field” : “ratings.rating”,
“size” : 10
},
“facet_filter” : {
“term” : { “ratings.owner” : “my_id” }
}
}
}

That seems to be working fine. The problem is when I have other filters in the 
mix.  If I am also filtering my query by other fields, I need to include those 
filters in my facet, so that I’m getting back facet counts that match the 
results with the other filters applied.  My problem is that I don’t know how to 
combine nested and non-nested filters in facet_filter.  If I just throw them in 
together, my counts all go to zero:

“facets” : {
“my_ratings” : {
“nested” : “ratings”,
“terms” : {
“field” : “ratings.rating”,
“size” : 10
},
“facet_filter” : {
“and” : [{
“term” : { “ratings.owner” : “my_id” }
},{
“term” : { “a_different_field” : “blah” }
}]
}
}
}

Here is a gist to demonstrate: 

https://gist.github.com/nathanmoon/8228507

It runs two queries, the first is the basic nested facet (returns what I would 
expect), and the last query is what I want to get working, but is returning no 
counts.

Thanks for any help!

Nathan

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/A3B6ECDB-9CB5-4532-A2F9-8EAA66B9EFD0%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.