# Searching multiple index with different fields

**URL:** https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485
**Category:** Elasticsearch
**Created:** [March 22, 2019, 11:47am UTC](https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485 "2019-03-22T11:47:31Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Omprakash\_Verma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/omprakash_verma/32/42589_2.png) [@Omprakash\_Verma](https://discuss.elastic.co/u/Omprakash_Verma)
#### Post date: [March 22, 2019, 11:47am UTC](https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485/1 "2019-03-22T11:47:31Z")

</div>

Hi,  
We are using ES and getting response properly for 1 index with search fields. I need suggestions of following :  
Problem : I have different objects like contact, account have records which is searchable by in account (name field will be used to search) where in contact (Email, phone field will be used to search)

1. Should I use 1 index and keep contact and account in same index with different type (account, contact) to separate the records.
2. Should I create 2 index, 1 for account and another for contact.

Whatever is preferrable, please give me search tips. How it will search based on different fields.

Thank you so much !

---

<div class="post-metadata">

### Author: ![Omprakash\_Verma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/omprakash_verma/32/42589_2.png) [@Omprakash\_Verma](https://discuss.elastic.co/u/Omprakash_Verma)
#### Post date: [March 26, 2019, 9:43am UTC](https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485/2 "2019-03-26T09:43:20Z")

</div>

Any comments ?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 26, 2019, 9:44am UTC](https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485/3 "2019-03-26T09:44:47Z")

</div>

What kind of object you want your user to get back? Is he/she looking for contacts or accounts?

---

<div class="post-metadata">

### Author: ![Omprakash\_Verma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/omprakash_verma/32/42589_2.png) [@Omprakash\_Verma](https://discuss.elastic.co/u/Omprakash_Verma)
#### Post date: [March 26, 2019, 9:55am UTC](https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485/4 "2019-03-26T09:55:36Z")

</div>

This will be mix kind of reply. Any contacts or account matching that keywords should return in form of 2 json arrays like :

{  
"accounts": [{account1, account2}],  
"contacts": [{contact1, contact2}]  
}

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 26, 2019, 10:09am UTC](https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485/5 "2019-03-26T10:09:25Z")

</div>

So I'd probably create one index per type of object:

```auto
PUT /accounts
PUT /contacts

```

Then add some documents:

```auto
PUT /accounts/_doc/account1
{ ... }
PUT /accounts/_doc/account2
{ ... }
PUT /contacts/_doc/contact1
{ ... }
PUT /contacts/_doc/contact2
{ ... }

```

And use then the multisearch API: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html)

```auto
$ cat requests
{"index" : "contacts"}
{"query" : {"match_all" : {}}}
{"index" : "accounts"}
{"query" : {"match_all" : {}}}

```

```auto
$ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch --data-binary "@requests"; echo

```

---

<div class="post-metadata">

### Author: ![Omprakash\_Verma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/omprakash_verma/32/42589_2.png) [@Omprakash\_Verma](https://discuss.elastic.co/u/Omprakash_Verma)
#### Post date: [March 26, 2019, 10:19am UTC](https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485/6 "2019-03-26T10:19:08Z")

</div>

Let me try the same. Thank you for your support.

---

<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: [April 23, 2019, 10:19am UTC](https://discuss.elastic.co/t/searching-multiple-index-with-different-fields/173485/7 "2019-04-23T10:19:22Z")

</div>

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