shrw
shrw

Reputation: 1795

elastic search fulltext search on multiple index

Design Query for elasticsearch:

I have 10 tables in my mysql database : news, emails, etc. Which i would sync into elasticsearch. and i want to search across all these tables in the same go. There are no relationship in tables and all have txt field in them. Just want to search in txt field .. so should i have multiple index or just 1 index.

How should i organize my indices:

Option 1 : Should i have just one elasticsearch index(with an attribute of table type) for all the tables

OR

Option 2 : Should i have just multiple elasticsearch index for all the tables

Considering:

Upvotes: 0

Views: 1900

Answers (2)

user13114350
user13114350

Reputation: 51

Also you could use the msearch to search multiple indices:

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html

Upvotes: 0

Joe - Check out my books
Joe - Check out my books

Reputation: 16895

Have multiple indices and query any number of them at any given time:

POST emails/_doc
{
  "txt": "abc"
}

POST news/_doc
{
  "txt": "ab"
}

GET emails,news/_search
{
  "query": {
    "query_string": {
      "default_field": "txt", 
      "query": "ab OR abc"
    }
  }
}

Wildcard index names are supported too in case you've got, say, timestamp-bucketed names such as emails_2020, emails_2019 etc:

GET em*,ne*/_search
...

Upvotes: 2

Related Questions