0
votes

this is how my mapping looks like

 {
   "state":"open",
   "settings":{
      "index":{
         "creation_date":"1453816191454",
         "number_of_shards":"5",
         "number_of_replicas":"1",
         "version":{
            "created":"1070199"
         },
         "uuid":"TfMJ4M0wQDedYSQuBz5BjQ"
      }
   },
   "mappings":{
      "Product":{
         "properties":{
            "index":"not_analyzed",
            "store":true,
            "type":"string"
         },
         "ProductName":{
            "type":"nested",
            "properties":{
               "Name":{
                  "store":true,
                  "type":"string"
               }
            }
         },
         "ProductCode":{
            "type":"string"
         },
         "Number":{
            "index":"not_analyzed",
            "store":true,
            "type":"string"
         },
         "id":{
            "index":"no",
            "store":true,
            "type":"integer"
         },
         "ShortDescription":{
            "store":true,
            "type":"string"
         },
         "Printer":{
            "_routing":{
               "required":true
            },
            "_parent":{
               "type":"Product"
            },
            "properties":{
               "properties":{
                  "RelativeUrl":{
                     "index":"no",
                     "store":true,
                     "type":"string"
                  }
               }
            },
            "PrinterId":{
               "index":"no",
               "store":true,
               "type":"integer"
            },
            "Name":{
               "store":true,
               "type":"string"
            }
         }
      },
      "aliases":[

      ]
   }
}

I would like to query Printer child object and get back the products. when I query like below using term query, It works for the case 2230 but when I give hl-2230, it doesnt return anything because Name field is analyzed. In this case, I need query_string to get expected results.

    {

   "query": {
      "has_child": {
      "type": "Printer",
      "query": {  
          "term": {
             "Name":  "2230"             
          }        
    }
  }
  }
}

When I try the query like that I am receiving [has_child] query does not support [query_string]]. I tried Match query and I get same message. Does has_child only work with term query? How can I achieve the expected results if this is the case?

   "query": {
      "has_child": {
      "type": "Printer",

"query_string": {
"default_field": "Name",
"query": "HL-2230"
}

  }
1

1 Answers

1
votes

You made a simple mistake. Use query_string inside query and you are good to go.

{
"query": {
  "has_child": {
     "type": "Printer",
     "query": {
        "query_string": {
           "default_field": "Name",
           "query": "HL-2230"
        }
      }
    }
  }
}