# Can you define an index on two fields?

**URL:** <https://discuss.elastic.co/t/can-you-define-an-index-on-two-fields/63231>\
**Category:** Elasticsearch\
**Created:** [October 17, 2016, 11:01pm UTC](https://discuss.elastic.co/t/can-you-define-an-index-on-two-fields/63231 "2016-10-17T23:01:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![EuclideanSearch](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@EuclideanSearch](https://discuss.elastic.co/u/EuclideanSearch)\
**Post date:** [October 17, 2016, 11:01pm UTC](https://discuss.elastic.co/t/can-you-define-an-index-on-two-fields/63231/1 "2016-10-17T23:01:02Z")

</div>

I know that Elasticsearch (and Lucene) index every field in a document. I was wondering whether there is a way to index on tow fields (much like RDBMS). For instance, most of our queries filter on two types (timestamp, id) (others also filter on an arbitrary third field). Is there a way to achieve this?

---

<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:** [October 17, 2016, 11:02pm UTC](https://discuss.elastic.co/t/can-you-define-an-index-on-two-fields/63231/2 "2016-10-17T23:02:54Z")

</div>

All fields are indexed by default, but you cannot do a combined one like you are referring to.  
You'd need to merge the fields into a new one and index that.

---

<div class="post-metadata">

**Author:** ![EuclideanSearch](https://avatars.discourse-cdn.com/v4/letter/e/c77e96/32.png) [@EuclideanSearch](https://discuss.elastic.co/u/EuclideanSearch)\
**Post date:** [October 17, 2016, 11:12pm UTC](https://discuss.elastic.co/t/can-you-define-an-index-on-two-fields/63231/3 "2016-10-17T23:12:08Z")

</div>

Thanks @warkolm . Just a question by what you mean by 'merge the fields'? Do you mean concatenating? For instance is there a way to 'merge' a timestamp (date) field and a String (id) field?

---

<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:** [October 18, 2016, 1:27am UTC](https://discuss.elastic.co/t/can-you-define-an-index-on-two-fields/63231/4 "2016-10-18T01:27:52Z")

</div>

Using something like `copy_to`.

---

<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, 10:11pm UTC](https://discuss.elastic.co/t/can-you-define-an-index-on-two-fields/63231/5 "2017-07-05T22:11:38Z")

</div>


