Size of nested array is always 0

Schema looks like this:

  "mappings": {
    "_doc": {
      "_all": {
        "enabled": false
      },
      "properties": {
        "category_boost": {
          "type": "nested",
          "properties" : {
            "category": {
              "type": "text",
              "index": false
            },
            "boost": {
              "type": "integer",
              "index": false
            }
          }
        }
      }
    }
  }

The document in elastic does have data:

"category_boost": [
    {
        "category": "A",
        "boost": 98
    },
    {
        "category": "B",
        "boost": 96
    },
    {
        "category": "C",
        "boost": 94
    },
],

Inside scoring function:

for (int i=0; i<doc['"'category_boost.boost'"'].size(); ++i) { if (doc['"'category_boost.category'"'][i].value.equals(params.category)) { boost = doc['"'category_boost.boost'"'][i].value; } }

Also tried length to get size of the array, but did help. Since it does not affect results, I tried to divide by size() and it throws division by zero error, so I conclude the size is 0.

Overall problem: have a map of category->boost which is dynamic and I cannot hardcode into schema. I tried type object with json object, but it turned out you cannot access those objects in scoring functions, therefore I went with arrays with defined types.

Hey,

from a quick peek at your data structure, the array is doc["category_boost"] rather than doc["category_boost.boost"].

Can you explain what you mean with dynamic in the map? Does it mean, it has different data types?

Also, have you taken a look at the nested datatype, as this might help you.

--Alex

I mean that each deployment will have different categories, so I can't add to schema categoryA, categoryB, etc.

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