How to retrieve children with its parent?

Hello All,

I am working on Parent-Child document in my current project. I want to
fetch parent documents and child documents with its parent document if
child documents satisfy search term.

Following is my current scenario and my questions.

Parent Document Mapping

Parent Document Name

Authors

Fields

AuthorCode

AuthorName

Parent Document Data

Id

AuthorName

1

John

2

Marry

3

Waulter

Child Document Mapping

Child Document Name

Book

Fields

BookName

Genre

Publisher

Child Document Data

ParentId/AuthorId

ChildId

BookName

Genre

Publisher

1

1

MerryChristmas

Family

McGrow

2

2

Johncarter

Adventure

Deitel

2

3

Java Bible

Programming

BPB

3

4

How to play flute

Self Study

Johnson

Now from above parent and child data, I would like to search term which is
start with “john”. So I would expect following output. Please note that I
would expect parent who satisfy search term and child (with ITS PARENT) who
satisfy search term. Following should be expected output. Last column of
following result explain why particular document does appear in search
result.

AuthorName

BookName

Genre

Publisher

Reason to display in result

John

N/A

N/A

N/A

Author name start with John(only parent doc will return)

Marry

Johncarter

Adventure

Deitel

Bookname start with John(Parent doc along with child doc return)

Waulter

flute

Self Study

Johnson

Publisher start with John(Parent doc along with child doc return)

So my question is How can we write query that return parent and child with
its parent?

Thank you?

--

Hi,

Well , you can't get both parent and child at same time because ES does
not have any concept of joins.
You can embed the authors and their books ( children as per your schema )
in 1 document itself , the "books" field being the nested one , and then
fire a query
matching your criteria ( i.e starting with 'john' here )
But this will give you hit per doc and you will get a document having 1
author and all his books even if only one of his book's fields has 'john'
keyword

Second approach can be using has_child or_has parent queries and doing
manual joining at client side

Regards
Gaurav

On Friday, November 23, 2012 3:10:49 AM UTC+5:30, hdvyas wrote:

Hello All,

I am working on Parent-Child document in my current project. I want to
fetch parent documents and child documents with its parent document if
child documents satisfy search term.

Following is my current scenario and my questions.

Parent Document Mapping

Parent Document Name

Authors

Fields

AuthorCode

AuthorName

Parent Document Data

Id

AuthorName

1

John

2

Marry

3

Waulter

Child Document Mapping

Child Document Name

Book

Fields

BookName

Genre

Publisher

Child Document Data

ParentId/AuthorId

ChildId

BookName

Genre

Publisher

1

1

MerryChristmas

Family

McGrow

2

2

Johncarter

Adventure

Deitel

2

3

Java Bible

Programming

BPB

3

4

How to play flute

Self Study

Johnson

Now from above parent and child data, I would like to search term which is
start with “john”. So I would expect following output. Please note that I
would expect parent who satisfy search term and child (with ITS PARENT) who
satisfy search term. Following should be expected output. Last column of
following result explain why particular document does appear in search
result.

AuthorName

BookName

Genre

Publisher

Reason to display in result

John

N/A

N/A

N/A

Author name start with John(only parent doc will return)

Marry

Johncarter

Adventure

Deitel

Bookname start with John(Parent doc along with child doc return)

Waulter

flute

Self Study

Johnson

Publisher start with John(Parent doc along with child doc return)

So my question is How can we write query that return parent and child with
its parent?

Thank you?

--

+1 : if you are searching for books, index books with all search fields. You are in the NoSQL world now and you must forget almost everything you know about relational databases.

In you use case, once the book has been written, the author name won't change. So it really make sense to index it within the book. It's like taking a snapshot of your book cover. Author is part of it.

Make sense?

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

Le 23 nov. 2012 à 07:19, Gaurav Bansal shehzada.gaurav@gmail.com a écrit :

Hi,

Well , you can't get both parent and child at same time because ES does not have any concept of joins.
You can embed the authors and their books ( children as per your schema ) in 1 document itself , the "books" field being the nested one , and then fire a query
matching your criteria ( i.e starting with 'john' here )
But this will give you hit per doc and you will get a document having 1 author and all his books even if only one of his book's fields has 'john' keyword

Second approach can be using has_child or_has parent queries and doing manual joining at client side

Regards
Gaurav

On Friday, November 23, 2012 3:10:49 AM UTC+5:30, hdvyas wrote:

Hello All,

I am working on Parent-Child document in my current project. I want to fetch parent documents and child documents with its parent document if child documents satisfy search term.

Following is my current scenario and my questions.

Parent Document Mapping

Parent Document Name
Authors
Fields
AuthorCode

AuthorName

Parent Document Data

Id
AuthorName
1
John
2
Marry
3
Waulter

Child Document Mapping

Child Document Name
Book
Fields
BookName

Genre

Publisher

Child Document Data

ParentId/AuthorId
ChildId
BookName
Genre
Publisher
1
1
MerryChristmas
Family
McGrow
2
2
Johncarter
Adventure
Deitel
2
3
Java Bible
Programming
BPB
3
4
How to play flute
Self Study
Johnson

Now from above parent and child data, I would like to search term which is start with “john”. So I would expect following output. Please note that I would expect parent who satisfy search term and child (with ITS PARENT) who satisfy search term. Following should be expected output. Last column of following result explain why particular document does appear in search result.

AuthorName
BookName
Genre
Publisher
Reason to display in result
John
N/A
N/A
N/A
Author name start with John(only parent doc will return)
Marry
Johncarter
Adventure
Deitel
Bookname start with John(Parent doc along with child doc return)
Waulter
flute
Self Study
Johnson
Publisher start with John(Parent doc along with child doc return)

So my question is How can we write query that return parent and child with its parent?

Thank you?

--

--

We are providing google like search(There will be single text box and user
will enter whatever they want to search) so client side operation will be
very costly for us. Any way I do really appreciated your help.....!! Thank
you

On Friday, November 23, 2012 8:19:34 AM UTC+2, Gaurav Bansal wrote:

Hi,

Well , you can't get both parent and child at same time because ES does
not have any concept of joins.
You can embed the authors and their books ( children as per your schema )
in 1 document itself , the "books" field being the nested one , and then
fire a query
matching your criteria ( i.e starting with 'john' here )
But this will give you hit per doc and you will get a document having 1
author and all his books even if only one of his book's fields has 'john'
keyword

Second approach can be using has_child or_has parent queries and doing
manual joining at client side

Regards
Gaurav

On Friday, November 23, 2012 3:10:49 AM UTC+5:30, hdvyas wrote:

Hello All,

I am working on Parent-Child document in my current project. I want to
fetch parent documents and child documents with its parent document if
child documents satisfy search term.

Following is my current scenario and my questions.

Parent Document Mapping

Parent Document Name

Authors

Fields

AuthorCode

AuthorName

Parent Document Data

Id

AuthorName

1

John

2

Marry

3

Waulter

Child Document Mapping

Child Document Name

Book

Fields

BookName

Genre

Publisher

Child Document Data

ParentId/AuthorId

ChildId

BookName

Genre

Publisher

1

1

MerryChristmas

Family

McGrow

2

2

Johncarter

Adventure

Deitel

2

3

Java Bible

Programming

BPB

3

4

How to play flute

Self Study

Johnson

Now from above parent and child data, I would like to search term which
is start with “john”. So I would expect following output. Please note that
I would expect parent who satisfy search term and child (with ITS PARENT)
who satisfy search term. Following should be expected output. Last column
of following result explain why particular document does appear in search
result.

AuthorName

BookName

Genre

Publisher

Reason to display in result

John

N/A

N/A

N/A

Author name start with John(only parent doc will return)

Marry

Johncarter

Adventure

Deitel

Bookname start with John(Parent doc along with child doc return)

Waulter

flute

Self Study

Johnson

Publisher start with John(Parent doc along with child doc return)

So my question is How can we write query that return parent and child
with its parent?

Thank you?

--

Hi David,

It makes sense. But in future Author may have other children. for example
author may have Publishers(Though right now we are making PublisherName
property in Book). So we are not able to create Author as a part of book.

But I do really appreciated your help............!!! Thank you......!!!

On Friday, November 23, 2012 8:53:27 AM UTC+2, David Pilato wrote:

+1 : if you are searching for books, index books with all search fields.
You are in the NoSQL world now and you must forget almost everything you
know about relational databases.

In you use case, once the book has been written, the author name won't
change. So it really make sense to index it within the book. It's like
taking a snapshot of your book cover. Author is part of it.

Make sense?

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

Le 23 nov. 2012 à 07:19, Gaurav Bansal <shehzad...@gmail.com <javascript:>>
a écrit :

Hi,

Well , you can't get both parent and child at same time because ES does
not have any concept of joins.
You can embed the authors and their books ( children as per your schema )
in 1 document itself , the "books" field being the nested one , and then
fire a query
matching your criteria ( i.e starting with 'john' here )
But this will give you hit per doc and you will get a document having 1
author and all his books even if only one of his book's fields has 'john'
keyword

Second approach can be using has_child or_has parent queries and doing
manual joining at client side

Regards
Gaurav

On Friday, November 23, 2012 3:10:49 AM UTC+5:30, hdvyas wrote:

Hello All,

I am working on Parent-Child document in my current project. I want to
fetch parent documents and child documents with its parent document if
child documents satisfy search term.

Following is my current scenario and my questions.

Parent Document Mapping

Parent Document Name

Authors

Fields

AuthorCode

AuthorName

Parent Document Data

Id

AuthorName

1

John

2

Marry

3

Waulter

Child Document Mapping

Child Document Name

Book

Fields

BookName

Genre

Publisher

Child Document Data

ParentId/AuthorId

ChildId

BookName

Genre

Publisher

1

1

MerryChristmas

Family

McGrow

2

2

Johncarter

Adventure

Deitel

2

3

Java Bible

Programming

BPB

3

4

How to play flute

Self Study

Johnson

Now from above parent and child data, I would like to search term which
is start with “john”. So I would expect following output. Please note that
I would expect parent who satisfy search term and child (with ITS PARENT)
who satisfy search term. Following should be expected output. Last column
of following result explain why particular document does appear in search
result.

AuthorName

BookName

Genre

Publisher

Reason to display in result

John

N/A

N/A

N/A

Author name start with John(only parent doc will return)

Marry

Johncarter

Adventure

Deitel

Bookname start with John(Parent doc along with child doc return)

Waulter

flute

Self Study

Johnson

Publisher start with John(Parent doc along with child doc return)

So my question is How can we write query that return parent and child
with its parent?

Thank you?

--

--