# How to set default value for rank\_feature field type

**URL:** <https://discuss.elastic.co/t/how-to-set-default-value-for-rank-feature-field-type/329694>\
**Category:** Elasticsearch\
**Created:** [April 11, 2023, 1:09am UTC](https://discuss.elastic.co/t/how-to-set-default-value-for-rank-feature-field-type/329694 "2023-04-11T01:09:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![binoiii](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/binoiii/32/97753_2.png) [@binoiii](https://discuss.elastic.co/u/binoiii)\
**Post date:** [April 11, 2023, 1:09am UTC](https://discuss.elastic.co/t/how-to-set-default-value-for-rank-feature-field-type/329694/1 "2023-04-11T01:09:13Z")

</div>

I'm performing a **rank\_feature query** and there is a possibility that the fields that I will rank i.e **bid field** (please below) won't be available.

I wonder if there is a way **to set a default** for **bid** if the field is not present.

For example, here is my **document mapping**

```auto
PUT /tier-sort-2
{
  "mappings": {
    "properties": {
      "popularity_scores": {
        "type": "nested",
        "properties": {
          "score": {
            "type": "rank_feature"
          },
          "study_field": {
            "type": "text"
          }
        }
      },
      "bid": {
        "type": "rank_feature"
      }
    }
  }
}

```

Here are my **test documents** :

```auto
POST _bulk
{"index":{"_index":"tier-sort","_id":"1"}}
{"title":"Job 1","popularity_scores":{"score":"0.105", "study_field":"45"}}
{"index":{"_index":"tier-sort","_id":"2"}}
{"title":"Job 2","popularity_scores":{"score":"0.06", "study_field":"45"},"bid":"50"}
{"index":{"_index":"tier-sort","_id":"3"}}
{"title":"Job 3","popularity_scores":{"score":"0.099", "study_field":"45"},"bid":"25"}
{"index":{"_index":"tier-sort","_id":"4"}}
{"title":"Job 4","popularity_scores":{"score":"0.155", "study_field":"45"},"bid":"5"}
{"index":{"_index":"tier-sort","_id":"5"}}
{"title":"Job 5","popularity_scores":{"score":"0.028", "study_field":"45"},"bid":"100"}

```

Here is my **query** :

```auto
GET tier-sort/_search
{
  "size": 100,
  "query": {
    "bool": {
      "should": [
        {
          "nested": {
            "path": "popularity_scores",
            "query": {
              "rank_feature": {
                "field": "popularity_scores.score",
                "boost": 1
              }
            }
          }
        },
        {
          "rank_feature": {
            "field": "bid",
            "boost": 1
          }
        }
      ]
    }
  }
}

```

As you can see, for document with **\_job="1"** , the **bid field** is no present.

Is there a way to set a default value that field i.e **bid="50"**

Thanks in advance!

---

<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:** [May 9, 2023, 1:09am UTC](https://discuss.elastic.co/t/how-to-set-default-value-for-rank-feature-field-type/329694/2 "2023-05-09T01:09:17Z")

</div>

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