IS there a way to search on parent fields from a nested query?

I wrote a query which works well on nested fields, but also wanted to add a functionality where it can search on the parent fields as well.

Here is the mapping:

mapping: {
   doc: {
     properties: {
        "name" : {"type":"text"},
       "address": {"type": "text"}
      "interests": {"type": "nested","properties": {"game":{"type":"text" }}}
}

i can do a nested query on it, but unable to query parent from the nested query (i.e name and address). If there is a way to do it, can somebody help?

The vice versa will also help, where from parent we can also query nested docs

Hello, Manish.
You can combine parent field query and nested one with bool/must.

Hi @Mikhail_Khludnev

I tried using must like this:

{
    "query": {
      "bool": {
        "must": [{
          "query": {
            "query_string": {
              "query": "test.pdf"
            }
          },
            "nested": {
              "path": ["files"],
              "query": {
                "query_string": {
                  "query": "test.pdf"
                }
              }
            }
            
          }]
          
          
      }
    }
}

But does not give me expected results, as test.pdf is a nested field, the query is coming in as dynamic string

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