# Lucene Expressions: get ALL values from a Multi Value Field

**URL:** <https://discuss.elastic.co/t/lucene-expressions-get-all-values-from-a-multi-value-field/157640>\
**Category:** Elasticsearch\
**Created:** [November 21, 2018, 7:39am UTC](https://discuss.elastic.co/t/lucene-expressions-get-all-values-from-a-multi-value-field/157640 "2018-11-21T07:39:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seperman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seperman/32/11550_2.png) [@seperman](https://discuss.elastic.co/u/seperman)\
**Post date:** [November 21, 2018, 7:39am UTC](https://discuss.elastic.co/t/lucene-expressions-get-all-values-from-a-multi-value-field/157640/1 "2018-11-21T07:39:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [November 21, 2018, 8:35pm UTC](https://discuss.elastic.co/t/lucene-expressions-get-all-values-from-a-multi-value-field/157640/2 "2018-11-21T20:35:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![seperman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seperman/32/11550_2.png) [@seperman](https://discuss.elastic.co/u/seperman)\
**Post date:** [November 24, 2018, 6:16am UTC](https://discuss.elastic.co/t/lucene-expressions-get-all-values-from-a-multi-value-field/157640/4 "2018-11-24T06:16:10Z")

</div>

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...

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 22, 2018, 6:16am UTC](https://discuss.elastic.co/t/lucene-expressions-get-all-values-from-a-multi-value-field/157640/5 "2018-12-22T06:16:19Z")

</div>

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