# Elasticsearch template query

**URL:** https://discuss.elastic.co/t/elasticsearch-template-query/113121
**Category:** Elasticsearch
**Created:** [December 25, 2017, 6:09am UTC](https://discuss.elastic.co/t/elasticsearch-template-query/113121 "2017-12-25T06:09:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jiangshigen](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@jiangshigen](https://discuss.elastic.co/u/jiangshigen)
#### Post date: [December 25, 2017, 6:09am UTC](https://discuss.elastic.co/t/elasticsearch-template-query/113121/1 "2017-12-25T06:09:55Z")

</div>

I use QueryBuilders.templateQuery(template, map) to achieve some documents, howerer,the relevance scoring of each document is 1.I hope someone can help me.

template example:  
{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"default\_field": "progress\_note",  
"query": "chest pains"  
}  
}  
],  
"must\_not": [],  
"should": []  
}  
},  
"from": 0,  
"size": 10,  
"sort": [],  
"aggs": {}  
}

---

<div class="post-metadata">

### Author: ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)
#### Post date: [December 27, 2017, 1:12pm UTC](https://discuss.elastic.co/t/elasticsearch-template-query/113121/2 "2017-12-27T13:12:16Z")

</div>

Hi @jiangshigen,

It's not clear to me the reason you are using a template query as your query is not a template at all.

Doing a normal query you get the expected score:

```
POST my_index/doc/1
{
  "progress_note": "chest pains"
}

GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "default_field": "progress_note",
            "query": "chest pains"
          }
        }
      ],
      "must_not": [],
      "should": []
    }
  },
  "from": 0,
  "size": 10,
  "sort": [],
  "aggs": {}
}

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.5753642,
    "hits": [
      {
        "_index": "my_index",
        "_type": "doc",
        "_id": "1",
        "_score": 0.5753642,
        "_source": {
          "progress_note": "chest pains"
        }
      }
    ]
  }
} 

```

Can you elaborate your question?

Cheers,  
LG

---

<div class="post-metadata">

### Author: ![jiangshigen](https://avatars.discourse-cdn.com/v4/letter/j/e9bcb4/32.png) [@jiangshigen](https://discuss.elastic.co/u/jiangshigen)
#### Post date: [January 18, 2018, 6:51am UTC](https://discuss.elastic.co/t/elasticsearch-template-query/113121/3 "2018-01-18T06:51:31Z")

</div>

Thank you for your answer.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/5/852b42b002b17ade707711abee7615f8cc0f907d.png)I use this way to achieve some documents, howerer,the relevance scoring of each document is 1.  
template example:  
{  
"query": {  
"bool": {  
"must": [  
{  
"query\_string": {  
"default\_field": "progress\_note",  
"query": "{{queryString}}"  
}  
}  
],  
"must\_not": ,  
"should":   
}  
},  
"from": 0,  
"size": 10,  
"sort": ,  
"aggs": {}  
}

---

<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: [February 15, 2018, 6:51am UTC](https://discuss.elastic.co/t/elasticsearch-template-query/113121/4 "2018-02-15T06:51:43Z")

</div>

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