1
votes

I has mapping:


    {
       "properties":{
          /*some fields ommited*/,
          "properties":{
             "type":"nested",
             "properties":{
                "FieldA":{
                   "type":"string",
                   "fields":{
                      "raw":{
                         "index":"not_analyzed",
                         "type":"string"
                      }
                   }
                }
             }
          }
       }
    }

and some documents:


    {
      /*some fields ommited*/,
       "properties":{
          "FieldA":"one"
       }
    }

    {
      /*some fields ommited*/,
       "properties":{
          "FieldA":"two"
       }
    }

and so on.

I try to make query:


    {
      "query": {
        "nested": {
          "query": {
            "term": {
              "FieldA.raw": "one"
            }
          },
          "path": "properties"
        }
      }
    }

There are no results found. If i try to use the same query by field with other type (not string, and without raw subfield) it works. How should i write query for that case? Thanks!

P.S. field "FieldA" has subfield raw because i need this field to be analyzed and not analyzed at the same time

1

1 Answers

3
votes

You just need to specify the full path to the nested field:

{
   "query": {
      "nested": {
         "path": "properties",
         "query": {
            "term": {
               "properties.FieldA.raw": "one"
            }
         }
      }
   }
}

Here is some code I used to test it:

http://sense.qbox.io/gist/f2d9e5eae7496ca0fce8d2d23e17bf4d72d9300a