0

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 Answer 1

1

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"
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

3 Comments

wow, that much simple. If I may ask you a quick question, which query might possibly return results for "hl2230" If name is indexed as "hl-2230". is it even possible?
Since your hl-2230 is analyzed and has generic_analyzer . It will be tokenized as hl and 2230. It means that there is no token saved as hl2230 in reverse index . So there is no way you can get results if you query hl2230. But you can get results by changing index analyser but that would need reindexing of your index
can you give me some tips about this? I made also separate question for it. stackoverflow.com/questions/35697941/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.