Facet_filter for different scopes

Hey, list.

I'm struggling with multifacet navigation, where facets are located in
different scopes.

Let's see example:

authors: {
'name': 'Mark Twain',
'country': 'US',
'books': [
{
'year': 1927
},
{
'year': 1935
}
]
}

Here books is a nested object.

I want to make facets on country and book years.
My problem is I can not do like this:

"facets": {
    "book-years": {
        "scope": "book-year-filter",
        "terms": {
            "field": "books.year"
        },
        "facet_filter": {
                "in": {
                    "country": [
                        "US", "GB"
                    ]
                }
        }
    }
},

How could I solve this?

--

Hello Rauan,

This should work:

"facets": {
    "book-years": {
        "terms": {
            "field": "year"
        },
        "nested": "books"
    }
}

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

On Thu, Oct 18, 2012 at 12:34 PM, Rauan Maemirov rauan1987@gmail.com wrote:

Hey, list.

I'm struggling with multifacet navigation, where facets are located in
different scopes.

Let's see example:

authors: {
'name': 'Mark Twain',
'country': 'US',
'books': [
{
'year': 1927
},
{
'year': 1935
}
]
}

Here books is a nested object.

I want to make facets on country and book years.
My problem is I can not do like this:

"facets": {
    "book-years": {
        "scope": "book-year-filter",
        "terms": {
            "field": "books.year"
        },
        "facet_filter": {
                "in": {
                    "country": [
                        "US", "GB"
                    ]
                }
        }
    }
},

How could I solve this?

--

--

That doesn't help.
I have troubles with facet_filter, but not with nested scope.

Le jeudi 18 octobre 2012 18:06:06 UTC+6, Radu Gheorghe a écrit :

Hello Rauan,

This should work:

"facets": { 
    "book-years": { 
        "terms": { 
            "field": "year" 
        }, 
        "nested": "books" 
    } 
} 

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

On Thu, Oct 18, 2012 at 12:34 PM, Rauan Maemirov <raua...@gmail.com<javascript:>>
wrote:

Hey, list.

I'm struggling with multifacet navigation, where facets are located in
different scopes.

Let's see example:

authors: {
'name': 'Mark Twain',
'country': 'US',
'books': [
{
'year': 1927
},
{
'year': 1935
}
]
}

Here books is a nested object.

I want to make facets on country and book years.
My problem is I can not do like this:

"facets": { 
    "book-years": { 
        "scope": "book-year-filter", 
        "terms": { 
            "field": "books.year" 
        }, 
        "facet_filter": { 
                "in": { 
                    "country": [ 
                        "US", "GB" 
                    ] 
                } 
        } 
    } 
}, 

How could I solve this?

--

--

On Thu, Oct 18, 2012 at 7:44 PM, Rauan Maemirov rauan1987@gmail.com wrote:

That doesn't help.
I have troubles with facet_filter, but not with nested scope.

Oh, I see. If your facet scope is "books", then your facet_filter also
looks in "books". And "country" is outside that scope.

You could use "include_in_parent" or "include_in_root" in your nested
mapping. Something like this:

curl -XPUT localhost:9200/test/test_nested/_mapping -d '
{
"test_nested": {
"properties": {
"books": {
"type": "nested",
"include_in_parent": true,
"properties": {
"year": {
"type": "long"
}
}
}
}
}
}'

Then, don't specify any scope to your facet (because "year" is now
included in the parent/root document), and the facet filter should
work as well, because "country" is already in the root doc. Something
like this:

"facets": {
    "book-years": {
        "terms": {
            "field": "year"
        },
        "facet_filter": {
            "terms": {
                "country": ["us","gb"]
            }
        }
    }
}

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

Le jeudi 18 octobre 2012 18:06:06 UTC+6, Radu Gheorghe a écrit :

Hello Rauan,

This should work:

"facets": {
    "book-years": {
        "terms": {
            "field": "year"
        },
        "nested": "books"
    }
}

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

On Thu, Oct 18, 2012 at 12:34 PM, Rauan Maemirov raua...@gmail.com
wrote:

Hey, list.

I'm struggling with multifacet navigation, where facets are located in
different scopes.

Let's see example:

authors: {
'name': 'Mark Twain',
'country': 'US',
'books': [
{
'year': 1927
},
{
'year': 1935
}
]
}

Here books is a nested object.

I want to make facets on country and book years.
My problem is I can not do like this:

"facets": {
    "book-years": {
        "scope": "book-year-filter",
        "terms": {
            "field": "books.year"
        },
        "facet_filter": {
                "in": {
                    "country": [
                        "US", "GB"
                    ]
                }
        }
    }
},

How could I solve this?

--

--

--

What if I have same property names for parent and nested objects?
Will parent prorepties be overwritten by nested?

And what is the difference between include_in_parent and include_in_root?

Le vendredi 19 octobre 2012 03:04:08 UTC+6, Radu Gheorghe a écrit :

On Thu, Oct 18, 2012 at 7:44 PM, Rauan Maemirov <raua...@gmail.com<javascript:>>
wrote:

That doesn't help.
I have troubles with facet_filter, but not with nested scope.

Oh, I see. If your facet scope is "books", then your facet_filter also
looks in "books". And "country" is outside that scope.

You could use "include_in_parent" or "include_in_root" in your nested
mapping. Something like this:

curl -XPUT localhost:9200/test/test_nested/_mapping -d '
{
"test_nested": {
"properties": {
"books": {
"type": "nested",
"include_in_parent": true,
"properties": {
"year": {
"type": "long"
}
}
}
}
}
}'

Then, don't specify any scope to your facet (because "year" is now
included in the parent/root document), and the facet filter should
work as well, because "country" is already in the root doc. Something
like this:

"facets": { 
    "book-years": { 
        "terms": { 
            "field": "year" 
        }, 
        "facet_filter": { 
            "terms": { 
                "country": ["us","gb"] 
            } 
        } 
    } 
} 

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

--

Thank you so much, getting rid of nested queries and using
include_in_parent helped to resolve the issue.

Le vendredi 19 octobre 2012 03:04:08 UTC+6, Radu Gheorghe a écrit :

On Thu, Oct 18, 2012 at 7:44 PM, Rauan Maemirov <raua...@gmail.com<javascript:>>
wrote:

That doesn't help.
I have troubles with facet_filter, but not with nested scope.

Oh, I see. If your facet scope is "books", then your facet_filter also
looks in "books". And "country" is outside that scope.

You could use "include_in_parent" or "include_in_root" in your nested
mapping. Something like this:

curl -XPUT localhost:9200/test/test_nested/_mapping -d '
{
"test_nested": {
"properties": {
"books": {
"type": "nested",
"include_in_parent": true,
"properties": {
"year": {
"type": "long"
}
}
}
}
}
}'

Then, don't specify any scope to your facet (because "year" is now
included in the parent/root document), and the facet filter should
work as well, because "country" is already in the root doc. Something
like this:

"facets": { 
    "book-years": { 
        "terms": { 
            "field": "year" 
        }, 
        "facet_filter": { 
            "terms": { 
                "country": ["us","gb"] 
            } 
        } 
    } 
} 

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

Le jeudi 18 octobre 2012 18:06:06 UTC+6, Radu Gheorghe a écrit :

Hello Rauan,

This should work:

"facets": { 
    "book-years": { 
        "terms": { 
            "field": "year" 
        }, 
        "nested": "books" 
    } 
} 

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

On Thu, Oct 18, 2012 at 12:34 PM, Rauan Maemirov raua...@gmail.com
wrote:

Hey, list.

I'm struggling with multifacet navigation, where facets are located
in
different scopes.

Let's see example:

authors: {
'name': 'Mark Twain',
'country': 'US',
'books': [
{
'year': 1927
},
{
'year': 1935
}
]
}

Here books is a nested object.

I want to make facets on country and book years.
My problem is I can not do like this:

"facets": { 
    "book-years": { 
        "scope": "book-year-filter", 
        "terms": { 
            "field": "books.year" 
        }, 
        "facet_filter": { 
                "in": { 
                    "country": [ 
                        "US", "GB" 
                    ] 
                } 
        } 
    } 
}, 

How could I solve this?

--

--

--

Hello Rauan,

On Fri, Oct 19, 2012 at 11:07 AM, Rauan Maemirov rauan1987@gmail.com wrote:

What if I have same property names for parent and nested objects?
Will parent prorepties be overwritten by nested?

No, they won't get overwritten, but the facet without "nested" in it
will only work for the "year" property in the parent doc. Which would
get you back to where you started :frowning:

And what is the difference between include_in_parent and include_in_root?

If you have multiple levels of nested, include_in_parent should add
your field to the immediate parent, while include_in_root should add
it to the root document. If you only have a single nested layer (like
in your example), both should mean the same. I haven't tested both
yet, but that's what I understand from here:

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

Le vendredi 19 octobre 2012 03:04:08 UTC+6, Radu Gheorghe a écrit :

On Thu, Oct 18, 2012 at 7:44 PM, Rauan Maemirov raua...@gmail.com wrote:

That doesn't help.
I have troubles with facet_filter, but not with nested scope.

Oh, I see. If your facet scope is "books", then your facet_filter also
looks in "books". And "country" is outside that scope.

You could use "include_in_parent" or "include_in_root" in your nested
mapping. Something like this:

curl -XPUT localhost:9200/test/test_nested/_mapping -d '
{
"test_nested": {
"properties": {
"books": {
"type": "nested",
"include_in_parent": true,
"properties": {
"year": {
"type": "long"
}
}
}
}
}
}'

Then, don't specify any scope to your facet (because "year" is now
included in the parent/root document), and the facet filter should
work as well, because "country" is already in the root doc. Something
like this:

"facets": {
    "book-years": {
        "terms": {
            "field": "year"
        },
        "facet_filter": {
            "terms": {
                "country": ["us","gb"]
            }
        }
    }
}

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

--

--