Searching root document and nested documents in facet query

Hi,
I have user document which contains nested tag documents. These tag
documents can be of varied types i.e it can be a tag of college, company,
user_type, course, etc. I want to implement a linked in type of people
search (http://www.linkedin.com/search/fpsearch?trk=tab_pro) in my
application. What I am trying to do is, when user selects any tag from the
search box. The facet count of various tags are updated and users are
filtered according to that tag. But while getting the facet counts for,
say, company, when I select company tag, the company facet count should not
be updated (as implemented in the people search of linked in).
Here is my user mapping:
{
"user" : {
"properties" : {
"tags" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "string",
"index" : "not_analyzed",
"store" : "yes"
},
"current" : {
"type" : "boolean"
},
"type" : {
"type" : "string"
},
"value" : {
"type" : "multi_field",
"fields" : {
"value" : {
"type" : "string",
"analyzer" : "name_analyzer"
},
"value_untouched" : {
"type" : "string",
"index" : "not_analyzed",
"include_in_all" : false
}
}
}
}
}
}
}
}
Here is the sample user document containing college and company tags
{
"tags": [
{
"type": "college",
"value": "Velammal Institute of Technology",
"id": "f96807dcac0f218f41ff67ecb5a4881ee4f93a3f"
},
{
"type": "company",
"value": "TCS-Tata consultancy services",
"id": "d3f91402aa0a795bf29dcc2295a804060c0a00f1"
},
{
"type": "company",
"value": "Google"
"id" : "d3f91402aa0a795bf29dcc2295a804060c0a00f1"
"current" : true
}
]
}
I want to get the filtered users and the facets in a single query to
implement the above. For this, I need to use query parts that are common
for computing filtered users and fetching facets in the "query" section of
ES query. The additional filter that will be used to filter out the users
to compute facet counts will be included in the "facet_filter" section of
ES query. Also, "facet_filter" will filter out the tag_types - i.e if I
want to get the facet of college tags only. I will used nested facet filter
to filter out the tags in the users.
Presently, I am able to filter out the tags using nested facet filter using
this query:
{
"query": {
"filtered": {
"query": {
"match_all": {

    }
  },
}

},
"facets": {
"company": {
"terms": {
"field": "tags.value.value_untouched",
"size": 0
},?
"nested": "tags",
"facet_filter": {
"term": {
"tags.type": "company"
}
}
}
}
}
My question is I want to filter out the user documents based on tags in the
facet filter like this:
{"nested" : {"path": "tags", "query": {"bool":{"must": [{term: {"tags.type"
=> "company"}}, {"term":{"tags.value.value_untouched" => "Google"}}]}}}}
The above subquery will filter out the user documents. Then I can filter
out the tags whose count I want to return, as given in the ES query above.

In general, Is there a way to filter out root document based on nested
queries and then compute nested facets in the "facet_filter" of ES query?

--
Thanks,
Aash

--
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.

Or Is there a another way the filter out the parent document using nested
queries to compute facets only i.e that query part will not be used in the
filtering users using the actual query ?

On Tue, Apr 30, 2013 at 11:35 AM, aash dhariya aash.discover@gmail.comwrote:

Hi,
I have user document which contains nested tag documents. These tag
documents can be of varied types i.e it can be a tag of college, company,
user_type, course, etc. I want to implement a linked in type of people
search (http://www.linkedin.com/search/fpsearch?trk=tab_pro) in my
application. What I am trying to do is, when user selects any tag from the
search box. The facet count of various tags are updated and users are
filtered according to that tag. But while getting the facet counts for,
say, company, when I select company tag, the company facet count should not
be updated (as implemented in the people search of linked in).
Here is my user mapping:
{
"user" : {
"properties" : {
"tags" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "string",
"index" : "not_analyzed",
"store" : "yes"
},
"current" : {
"type" : "boolean"
},
"type" : {
"type" : "string"
},
"value" : {
"type" : "multi_field",
"fields" : {
"value" : {
"type" : "string",
"analyzer" : "name_analyzer"
},
"value_untouched" : {
"type" : "string",
"index" : "not_analyzed",
"include_in_all" : false
}
}
}
}
}
}
}
}
Here is the sample user document containing college and company tags
{
"tags": [
{
"type": "college",
"value": "Velammal Institute of Technology",
"id": "f96807dcac0f218f41ff67ecb5a4881ee4f93a3f"
},
{
"type": "company",
"value": "TCS-Tata consultancy services",
"id": "d3f91402aa0a795bf29dcc2295a804060c0a00f1"
},
{
"type": "company",
"value": "Google"
"id" : "d3f91402aa0a795bf29dcc2295a804060c0a00f1"
"current" : true
}
]
}
I want to get the filtered users and the facets in a single query to
implement the above. For this, I need to use query parts that are common
for computing filtered users and fetching facets in the "query" section of
ES query. The additional filter that will be used to filter out the users
to compute facet counts will be included in the "facet_filter" section of
ES query. Also, "facet_filter" will filter out the tag_types - i.e if I
want to get the facet of college tags only. I will used nested facet filter
to filter out the tags in the users.
Presently, I am able to filter out the tags using nested facet filter
using this query:
{
"query": {
"filtered": {
"query": {
"match_all": {

    }
  },
}

},
"facets": {
"company": {
"terms": {
"field": "tags.value.value_untouched",
"size": 0
},?
"nested": "tags",
"facet_filter": {
"term": {
"tags.type": "company"
}
}
}
}
}
My question is I want to filter out the user documents based on tags in
the facet filter like this:
{"nested" : {"path": "tags", "query": {"bool":{"must": [{term:
{"tags.type" => "company"}}, {"term":{"tags.value.value_untouched" =>
"Google"}}]}}}}
The above subquery will filter out the user documents. Then I can filter
out the tags whose count I want to return, as given in the ES query above.

In general, Is there a way to filter out root document based on nested
queries and then compute nested facets in the "facet_filter" of ES query?

--
Thanks,
Aash

--
Thanks,
Aash

--
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.