Search in both parent and child


#1

Hey,
I'm looking for a solution for the following problem, maybe someone can help me:

I'd like to index documents with a parent-child relationship and be able to search for parent-documents where the search string (provided by users, it could be something like "car sharing") can be only in the parent, only in the child or spreaded in parent and child.

The only solution I could think of so far is splitting the search string and creating a query in which every single term must be in either parent or child. This could result in quiet complex queries, depending on the user input (e.g. "(car AND (sharing OR dealer)").

Is there a way to do this without splitting the search string before and creating a complex query?

There is normaly only one parent and one child document but frequent updates to the child document (that's also the reason for splitting it in parent and child).

Thanks in advance,
Jul


(Adrien Grand) #2

Why do you need to split the search string first? You could do something that looks like:

{
  "query": {
    "bool": {
      "should": [
        {
           // your query on children goes here
         },
        {
          "has_child": {
            "type" : "your_child_type",
            // your query on children goes here again
          }
        }
      ]
    }
  }
}

(Adrien Grand) #3

Oh maybe I get why now, if your query is foo AND bar, you want to match if foo can be found in the parent and bar in a child? If yes, then this is more complicated indeed. My advice would be to not do it and instead look into whether attributes of the parent can be copied in the child documents to avoid having to do a join for every token in the query string.


#4

I'd like to seperate a document into two as part of the document is updated quite frequently. The part which is not updated frequently takes a lot of time to analyze, so I'd like to avoid updating it if not neccessary (this also rules out nested objects).

Any other recomendations?

Thanks!


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.