Search querystring for combining parent and child docs

Hi Friends

I'm new in Elastic Search. i'm developing asp.net(c#) search application using ES.

i have used two tables. First one is Parent table and another one is Child Table. i can able to retrieve parent records using HasChildQuery. what my question is , i want to combine the parent and child table queries in single search query.

Ex:

Parent Table : [parent_type]

PC1 | PC2 | PC3 | PC4

R1 A B C
R2 AA BB CC
R3 AAA BBB CCC

Child Table : [child_type]

PC1 | CC1 | CC2 | CC3

R1 X Y Z
R1 XX YY ZZ
R2 XXX YYY ZZZ

I need the query string like this.

( PC1:"R1" AND [child_type].CC1:"XX" )

Please provide the querystring for the above.

Note: Earlier i have used Lucene.Net. Now i converted into Elastic Search and using the Lucene parcer.

You can nest your HasChildQuery inside a bool query and also add any
parent clauses to the bool query:

Something like this should work:
"query" : {
"bool" : {
"must" : [
{ "term" : { "PC1" : "R1" } },
{ "has_child" : {"type" : "child_type", "query" : {"term"
: {"CC1" : "XX"}}}}
]
}
}

The above query should return R1.

Martijn

On 16 October 2012 12:25, ganesanmarappan ganesmca@gmail.com wrote:

Hi Friends

I'm new in Elastic Search. i'm developing asp.net(c#) search application
using ES.

i have used two tables. First one is Parent table and another one is Child
Table. i can able to retrieve parent records using HasChildQuery. what my
question is , i want to combine the parent and child table queries in single
search query.

Ex:

Parent Table : [parent_type]

PC1 | PC2 | PC3 | PC4

R1 A B C
R2 AA BB CC
R3 AAA BBB CCC

Child Table : [child_type]

PC1 | CC1 | CC2 | CC3

R1 X Y Z
R1 XX YY ZZ
R2 XXX YYY ZZZ

I need the query string like this.

( PC1:"R1" AND [child_type].CC1:"XX" )

Please provide the querystring for the above.

Note: Earlier i have used Lucene.Net. Now i converted into Elastic Search
and using the Lucene parcer.

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/search-querystring-for-combining-parent-and-child-docs-tp4024046.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

--
Met vriendelijke groet,

Martijn van Groningen

--

Thanks Martijn. The given seneario we have implemented and working fine for simple queries. if the query is complicated like below..

( PC1:"R1" AND [child_type].CC1:"XX" ) OR (( PC1:"R2" OR [child_type].CC1:"XXX" ) AND PC4:"CCC")

we are unable to build the query using HasChild.

Please let us know if query can be framed like [child_type].CC1:"XX" in querystring search.

Thanks Martijn. The given seneario we have implemented and working fine for simple queries. if the query is complicated like below..

( PC1:"R1" AND [child_type].CC1:"XX" ) OR (( PC1:"R2" OR [child_type].CC1:"XXX" ) AND PC4:"CCC")

we are unable to build the query using HasChild.

Please let us know if query can be framed like [child_type].CC1:"XX" in querystring search.

On Tue, 2012-10-16 at 04:25 -0700, Ganesan Marappan wrote:

Thanks Martijn. The given seneario we have implemented and working fine for
simple queries. if the query is complicated like below..

( PC1:"R1" AND [child_type].CC1:"XX" ) OR (( PC1:"R2" OR
[child_type].CC1:"XXX" ) AND PC4:"CCC")

we are unable to build the query using HasChild.

Please let us know if query can be framed like [child_type].CC1:"XX" in
querystring search.

Don't try to express your entire query in the query_string - it is
complicated, difficult to debug, and prone to error.

The Query DSL is your friend.

clint

--