0

I have trouble Accessing some multivalued array in my Elasticsearch index I use the query in retrieving the multivalued array from elasticsearch But I got null poiter exception for some of my documents in the index where the array given for search is present .This occures when I use queryString query instead of match_all

{
took: 3
timed_out: false
_shards: {
    total: 2
    successful: 1
    failed: 1
    failures: [
        {
            status: 500
            reason: NullPointerException[null]
        }
    ]
}

My query is

{
 "query":{
  "query_string":{
  "query":"report","default_field":"Content"
 }
},
"script_fields": {
"entity_facets": {
"script": "result=[];foreach(facet : _source.Categories.Types.Events)      

{if(facet.event==event) result.add(facet);} result",
 "params": {
 "event":"AnalystEvent"
  }
  }
 }

}

EDIT : I have an index https://gist.github.com/4129488 which I got by running query

 {
  "from": "0",
  "size": "100",
  "query": {
   "bool": {
   "must": [
   {
    "bool": {
    "must": [
    {
     "query_string": {
     "query": "confronted",
     "default_field":"Content"
    }
   },
   {
    "range": {
    "actualTimeStamp": {
    "from": "23-07-2012 10:04:52",
    "to": "23-09-2012 10:04:52"
   }
 }
 }
  ]
 }
 },
 {
  "bool": {
  "should": [
  {
    "fuzzy": {
    "SourceName": {
     "value": "Economic_Times"
   }
   }
   },
   {
     "fuzzy": {
     "SourceName": {
     "value": "reuters"
    }
   }
  }
 ]
 }
}
]
}
}
}

But I didn' get this index when using script field on th above query !!

Community
  • 1
  • 1
user1790894
  • 407
  • 3
  • 9
  • 17
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Elikill58 May 04 '23 at 08:55

1 Answers1

0

You, probably, have a record, which doesn't store _source, or its _source doesn't have Categories, or categories don't have any Types or Types don't have any Events. Just add if statements to check for these conditions.

imotov
  • 28,277
  • 3
  • 90
  • 82
  • I checked my index thorughly and there is nothing wrong as you said .I edited my post pleas review.Anticipating your help to sort the problem :( – user1790894 Nov 22 '12 at 05:13
  • I tested it with your record and it doesn't fail for me https://gist.github.com/58e7a59e69a39b8d361c – imotov Nov 22 '12 at 12:24
  • thanks for your effort .The point it fails was when my index has huge data I think.When I searched in an index having less number of data there is nothing get fails – user1790894 Nov 23 '12 at 03:35