# Combine two fields in search

**URL:** <https://discuss.elastic.co/t/combine-two-fields-in-search/284277>\
**Category:** Elasticsearch\
**Created:** [September 15, 2021, 11:30am UTC](https://discuss.elastic.co/t/combine-two-fields-in-search/284277 "2021-09-15T11:30:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![markuso](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@markuso](https://discuss.elastic.co/u/markuso)\
**Post date:** [September 15, 2021, 11:30am UTC](https://discuss.elastic.co/t/combine-two-fields-in-search/284277/1 "2021-09-15T11:30:30Z")

</div>

Hey,

I have the JSON data in elasticsearch as

```auto
{
  "prefix": "+46",
  "number":"123456789"
}

```

So this is a phone number, together with the country code prefix.

And searching for them as separate

prefix: +46  
number: 123456789

is very easy, but I want to have one string to be able to match it like

phoneNumber: +46123456789

Since this search doesn't know how long the prefix it, I would like to combine the two fields somehow.

And I dont want to edit all the existing data to add a field that contains the two of them combined.

Is there any smart way I can solve this?

Edit:  
Running elasticsearch 7.6.2

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 15, 2021, 10:29pm UTC](https://discuss.elastic.co/t/combine-two-fields-in-search/284277/2 "2021-09-15T22:29:30Z")

</div>

A few options;

- Upgrade to 7.14 and use a runtime field to merge them
- Merge the values into another field during ingestion
- Merge the values into another field with a reindex
- Use [Script query | Elasticsearch Guide [7.14] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html)

---

<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:** [October 13, 2021, 10:29pm UTC](https://discuss.elastic.co/t/combine-two-fields-in-search/284277/3 "2021-10-13T22:29:32Z")

</div>

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