You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "Alisa Z." <pr...@mail.ru> on 2016/03/16 20:10:27 UTC
[nested] how to specify a path for multiple nesting?
Hi all,
I have a deeply multi-level data structure (up to 6-7 levels deep) where due to the nature of the data some nested documents can have same type names at various levels. How to form a proper query on a nested field that would contain "a path" that defines that field?
I'll clarify with an example:
Reduced dataset:
[
{
id : book1,
type_s:book,
title_t : "The Way of Kings",
author_s : "Brandon Sanderson",
_childDocuments_ : [
{
id: book1_c1,
type_s:body,
text_t:"body text of the book... ",
_childDocuments_:[
{id: book2_c1_e1,
type_s:"keywords",
text_t:["The Matrix", "Neo", "character", "somebody", ...]}
]
},
{ id: book1_c2,
type_s:title,
text_t:"This book was too long.",
_childDocuments_:[
{id: book2_c1_e1,
type_s:"keywords",
text_t:["The Matrix", "Neo"]}
]
}
]
},
...
]
So there are different paths to text_t field:
* book.body.keywords.text_t
* book.title.keywords.text_t
I need to write a query that returns, say, all books which have keyword "Neo" in their title (not body).
I tried :
(1) q={!parent which=type_s:book}type_s:keywords AND text_t:Neo
which is obviously incorrect (returns both books whose body keywords and title keywords contain Neo):
(2) q={!parent which=type_s:book}type_s:body^=0{!parent which=type_s:body}type_s:keywords AND text_t:Neo
which does not return correct results (and I am not quite sure what it really does, I just saw it in another thread of this mailing list)
Can you help me to understand whether it is possible?
Or do I have to give unique types for documents at different levels of nesting (e.g., type_s:body_keywords & type_s:title_keywords)? I am trying to avoid, finding a way to specify a path would be much much more preferable.
Thank you in advance and looking forward to hearing from you
--
Alisa Zhila
Re[2]: [nested] how to specify a path for multiple nesting?
Posted by "Alisa Z." <pr...@mail.ru>.
Thanks, Mikhail.
I eventually added a distinguishing field "path" and queried unambiguously.
>Четверг, 17 марта 2016, 9:46 -04:00 от Mikhail Khludnev <mk...@griddynamics.com>:
>
>Hello,
>
>Please find inline
>
>On Wed, Mar 16, 2016 at 10:10 PM, Alisa Z. < proloxx@mail.ru > wrote:
>> Hi all,
>>I have a deeply multi-level data structure (up to 6-7 levels deep) where due to the nature of the data some nested documents can have same type names at various levels. How to form a proper query on a nested field that would contain "a path" that defines that field?
>>
>>I'll clarify with an example:
>>
>>Reduced dataset:
>>
>>[
>> {
>> id : book1,
>> type_s:book,
>> title_t : "The Way of Kings",
>> author_s : "Brandon Sanderson",
>> _childDocuments_ : [
>> {
>> id: book1_c1,
>> type_s:body,
>> text_t:"body text of the book... ",
>> _childDocuments_:[
>> {id: book2_c1_e1,
>> type_s:"keywords",
>> text_t:["The Matrix", "Neo", "character", "somebody", ...]}
>> ]
>> },
>> { id: book1_c2,
>> type_s:title,
>> text_t:"This book was too long.",
>> _childDocuments_:[
>> {id: book2_c1_e1,
>> type_s:"keywords",
>> text_t:["The Matrix", "Neo"]}
>> ]
>> }
>> ]
>> },
>> ...
>>]
>>
>>So there are different paths to text_t field:
>>* book.body.keywords.text_t
>>* book.title.keywords.text_t
>>I need to write a query that returns, say, all books which have keyword "Neo" in their title (not body).
>>I tried :
>>
>>(1) q={!parent which=type_s:book}type_s:keywords AND text_t:Neo
>>which is obviously incorrect (returns both books whose body keywords and title keywords contain Neo):
>>
>>(2) q={!parent which=type_s:book}type_s:body^=0{!parent which=type_s:body}type_s:keywords AND text_t:Neo
>
>I'd say this might work, however I prefer to use v=$foo to break query unambiguously. And also https://lucidworks.com/blog/2011/12/28/why-not-and-or-and-not/ but make sure that + is encoded as %2B in url.
>
>q={!parent which=type_s:book v=$titles}&titles=+type_s:title^=0 +{!parent which='type_s:(body title book)' v=$keywords}&keywords=+type_s:keywords^=0 +text_t:Neo
>
>specifying all sibling scopes discriminators is a black magic of block join (if it ever works). Please get back with parsed query (from debugQuery=true) and actual/expected result. Anyway, explicitly resolving scopes (type_s:body_keywords, type_s:title_keywords) might be much maintainable.
>
> which does not return correct results (and I am not quite sure what it really does, I just saw it in another thread of this mailing list)
>>
>>Can you help me to understand whether it is possible?
>>Or do I have to give unique types for documents at different levels of nesting (e.g., type_s:body_keywords & type_s:title_keywords)? I am trying to avoid, finding a way to specify a path would be much much more preferable.
>>
>>
>>Thank you in advance and looking forward to hearing from you
>>--
>>Alisa Zhila
>
>
>--
>Sincerely yours
>Mikhail Khludnev
>Principal Engineer,
>Grid Dynamics
>
>
>
Re: [nested] how to specify a path for multiple nesting?
Posted by Mikhail Khludnev <mk...@griddynamics.com>.
Hello,
Please find inline
On Wed, Mar 16, 2016 at 10:10 PM, Alisa Z. <pr...@mail.ru> wrote:
> Hi all,
> I have a deeply multi-level data structure (up to 6-7 levels deep) where
> due to the nature of the data some nested documents can have same type
> names at various levels. How to form a proper query on a nested field that
> would contain "a path" that defines that field?
>
> I'll clarify with an example:
>
> Reduced dataset:
>
> [
> {
> id : book1,
> type_s:book,
> title_t : "The Way of Kings",
> author_s : "Brandon Sanderson",
> _childDocuments_ : [
> {
> id: book1_c1,
> type_s:body,
> text_t:"body text of the book... ",
> _childDocuments_:[
> {id: book2_c1_e1,
> type_s:"keywords",
> text_t:["The Matrix", "Neo", "character", "somebody", ...]}
> ]
> },
> { id: book1_c2,
> type_s:title,
> text_t:"This book was too long.",
> _childDocuments_:[
> {id: book2_c1_e1,
> type_s:"keywords",
> text_t:["The Matrix", "Neo"]}
> ]
> }
> ]
> },
> ...
> ]
>
> So there are different paths to text_t field:
> * book.body.keywords.text_t
> * book.title.keywords.text_t
> I need to write a query that returns, say, all books which have keyword
> "Neo" in their title (not body).
> I tried :
>
> (1) q={!parent which=type_s:book}type_s:keywords AND text_t:Neo
> which is obviously incorrect (returns both books whose body keywords and
> title keywords contain Neo):
>
> (2) q={!parent which=type_s:book}type_s:body^=0{!parent
> which=type_s:body}type_s:keywords AND text_t:Neo
>
I'd say this might work, however I prefer to use v=$foo to break query
unambiguously. And also
https://lucidworks.com/blog/2011/12/28/why-not-and-or-and-not/ but make
sure that + is encoded as %2B in url.
q={!parent which=type_s:book v=$titles}&titles=+type_s:title^=0 +{!parent
which='type_s:(body title book)' v=$keywords}&keywords=+type_s:keywords^=0
+text_t:Neo
specifying all sibling scopes discriminators is a black magic of block join
(if it ever works). Please get back with parsed query (from
debugQuery=true) and actual/expected result. Anyway, explicitly resolving
scopes (type_s:body_keywords, type_s:title_keywords) might be much
maintainable.
> which does not return correct results (and I am not quite sure what it
> really does, I just saw it in another thread of this mailing list)
>
> Can you help me to understand whether it is possible?
> Or do I have to give unique types for documents at different levels of
> nesting (e.g., type_s:body_keywords & type_s:title_keywords)? I am trying
> to avoid, finding a way to specify a path would be much much more
> preferable.
>
>
> Thank you in advance and looking forward to hearing from you
> --
> Alisa Zhila
--
Sincerely yours
Mikhail Khludnev
Principal Engineer,
Grid Dynamics
<http://www.griddynamics.com>
<mk...@griddynamics.com>