# How to get list as term value in params for custom script plugin

**URL:** <https://discuss.elastic.co/t/how-to-get-list-as-term-value-in-params-for-custom-script-plugin/234279>\
**Category:** Elasticsearch\
**Created:** [May 26, 2020, 8:30am UTC](https://discuss.elastic.co/t/how-to-get-list-as-term-value-in-params-for-custom-script-plugin/234279 "2020-05-26T08:30:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dahea\_Moon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dahea_moon/32/50610_2.png) [@Dahea\_Moon](https://discuss.elastic.co/u/Dahea_Moon)\
**Post date:** [May 26, 2020, 8:30am UTC](https://discuss.elastic.co/t/how-to-get-list-as-term-value-in-params-for-custom-script-plugin/234279/1 "2020-05-26T08:30:20Z")

</div>

I'm making custom score script plugin for scoring based on payload value.

I've done with scoring logic, but it's working properly when it receives only one term.

I want to receive several analyzed terms in query. How can I receive several terms as array or list in params?

```
params: {"field": "field", "term": ["term1", "term2", "term3"]}

```

i want this type of params to work.

here is my code. I followed script example in elasticsearch github.  
i'm working with gradle and java 14.

```
private PayloadScoreLeafFactory(Map<String, Object> params, SearchLookup lookup) {
            if (!params.containsKey("field")) {
                throw new IllegalArgumentException("Missing parameter [field]");
            }
            if (!params.containsKey("term")) {
                throw new IllegalArgumentException("Missing parameter [term]");
            }
            this.params = params;
            this.lookup = lookup;
            field = params.get("field").toString();
            term = params.get("term").toString();
        }

        @Override
        public boolean needs_score() {
            return false;
        }

        @Override
        public ScoreScript newInstance(LeafReaderContext context) throws IOException {
            PostingsEnum postings = context.reader().postings(new Term(field, term), PostingsEnum.PAYLOADS);
            if (postings == null) {
                return new ScoreScript(params, lookup, context) {
                    @Override
                    public double execute(ExplanationHolder explanation) {
                        return 0.0d;
                    }
                };
            }
            return new ScoreScript(params, lookup, context) {
                int currentDocid = -1;
                @Override
                public void setDocument(int docid) {
                    if (postings.docID() < docid) {
                        try {
                            postings.advance(docid);
                        } catch (IOException e) {
                            throw new UncheckedIOException(e);
                        }
                    }
                    currentDocid = docid;
                }

                @Override
                public double execute(ExplanationHolder explanation) {
                    if (postings.docID() != currentDocid) {
                        return 0.0d;
                    }
                    try {
                        int freq = postings.freq();
                        float sum_of_payload = 0.0f;
                        for (int i=0; i<freq; i++) {
                            postings.nextPosition();
                            BytesRef payload = postings.getPayload();
                            if (payload != null) {
                                sum_of_payload += ByteBuffer.wrap(payload.bytes, payload.offset, payload.length)
                                        .order(ByteOrder.BIG_ENDIAN).getFloat();
                            }
                        }
                        return sum_of_payload;
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                }
            };
        }
    }
}
```

---

<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:** [June 23, 2020, 8:30am UTC](https://discuss.elastic.co/t/how-to-get-list-as-term-value-in-params-for-custom-script-plugin/234279/2 "2020-06-23T08:30:24Z")

</div>

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