Nested type field not found in Nested Script Filter Query


(Rahul Garg) #1

Mapping is given below:-

"properties": {
      "id": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "accounts": {
        "type": "nested",
        "properties": {
           "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
         "createdOn": {
            "type": "date"
          },
          "updatedOn": {
            "type": "date"
          }
        }
      }
    }

Scripted Query is :-

    {
    "query": {
      "bool": {
       "must":[
        {
          "nested": {
            "path": "accounts",
             "query": {
              "bool": {
               "filter" : {
                 "script" : {
                   "script" : "if( doc.containsKey('accounts') && doc['accounts'].size() == 1 ) { return true } else {return false}"
                 }
               }
             }
           }
         }
       }
     ]
    }
  },
   "size":1
  }

doc.containsKey('accounts') always returns false even if there are data is present.

ElasticSearch Version : 5.5.2


(system) #2

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