Searching multiple index with different fields

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 !

Any comments ?

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

1 Like

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}]
}

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

PUT /accounts
PUT /contacts

Then add some documents:

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

$ cat requests
{"index" : "contacts"}
{"query" : {"match_all" : {}}}
{"index" : "accounts"}
{"query" : {"match_all" : {}}}
$ curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch --data-binary "@requests"; echo
1 Like

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

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