# How to write elasticsearch script\_score in java api

**URL:** <https://discuss.elastic.co/t/how-to-write-elasticsearch-script-score-in-java-api/44790>\
**Category:** Elasticsearch\
**Created:** [March 18, 2016, 4:15am UTC](https://discuss.elastic.co/t/how-to-write-elasticsearch-script-score-in-java-api/44790 "2016-03-18T04:15:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin\_yuan](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@kevin\_yuan](https://discuss.elastic.co/u/kevin_yuan)\
**Post date:** [March 18, 2016, 4:15am UTC](https://discuss.elastic.co/t/how-to-write-elasticsearch-script-score-in-java-api/44790/1 "2016-03-18T04:15:46Z")

</div>

I find a function in ElasticSearch like

```
GET /_search
{
  "function_score": {
    "functions": [
      { ...location clause... }, 
      { ...price clause... }, 
      {
        "script_score": {
          "params": { 
            "threshold": 80,
            "discount": 0.1,
            "target": 10
          },
          "script": "price = doc['price'].value; margin = doc['margin'].value;
          if (price < threshold) { return price * margin / target };
          return price * (1 - discount) * margin / target;" 
        }
      }
    ]
  }
}

```

- I use ScoreFunctionBuilder to achive the "location caluse" and "price caluse" ,but I do not know how to write "script\_score" and "script" by java api
- The ES version in my project is 2.2.0 and I use the java api to achieve this function
- But I can not find the API like ScriptScoreFunctionBuilder. scriptFunction(String script,  
Map\<String, Object\> params) how can I do？ Thx 🙂

---

<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:** [July 5, 2017, 11:07pm UTC](https://discuss.elastic.co/t/how-to-write-elasticsearch-script-score-in-java-api/44790/2 "2017-07-05T23:07:20Z")

</div>


