Lucene Expressions: get ALL values from a Multi Value Field

Hello,

How do I get all the values in a numeric multi value field in Lucene Expressions. It return the minimum value by default. And I can ask for mean or min or max but not ALL values.

Basically I'm storing a vector as a multi value numeric field and want to do some calculations on the vector.

Example:

PUT employees
{
  "settings":{
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}


PUT employees/_mapping/map1'
{
  "properties": {
    "age": {
      "type": "integer"
    },
    "name": {
      "type": "keyword"
    },
    "skills": {
      "type": "integer"
    }

  }
}

PUT employees/sales/1/
{
  "age":521,
  "name":"James1",
  "skills":[5,1]
}

PUT employees/sales/2/
{
  "age":522,
  "name":"James1",
  "skills":[4,10]
}


POST employees/_search
{
    "query": {
        "function_score": {
            "boost_mode": "replace",
            "functions": [
                {
                    "script_score": {
                        "script": {
                            "inline": "doc['skills'].value",
                            "lang": "expression",
                            "params": {
                            }
                        }
                    }
                }
            ],
            "query": {
              "match_all": {}
            },
            "score_mode": "sum"
        }
    }
}

Thanks,
Sep

Unfortunately expressions (in Elasticsearch) are hard coded to only expose a single value (for a multi valued field, the first value is exposed). However, you can access all values of a field through painless. I suggest you try that. The performance should be roughly the same.

Thanks @rjernst
Since the order of items is important for me (I'm putting a vector there), seems like multi value field is not the right container type for vectors. I'm gonna look into how to write ES plugins. In the mean time I will just put each element of the vector as its own field in ES document which is really ugly...

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