Andy
Andy

Reputation: 735

I dont think i fully understand Elastic Search

I'm trying to understand something about Elastic Search and wondered if someone could help me figure it out.

The issue i have is how many indexes should i maintain and if theres a risk with too many of them. Lets say i want to index books in a library and want to be able to search:

As i see understand it ES is a Document storage engine meaning that datatypes are stored as opposed to normalized RDMS structure. The complication i have is do i create one datatype and store just that or should i create others?

How would i store the data to be able to search the following combinations:

  1. All Authors by Publisher X
  2. All Chapter Names in Book Names beginning with B and by Publisher Y
  3. All Publishers for books written by Author X with Chapter Name Y

I'm wondering if i have to create an index for chapters where each chapter then has a list of all publishers that feature that book.

Am i over complicating this?

Upvotes: 1

Views: 132

Answers (1)

pkhlop
pkhlop

Reputation: 1844

From what I see in your question, you need to create only one index (database analogue in MySQL), inside this index you will need to use content type (like table in MySQL) and each book will be a document inside datatype (like row in MySQL)

You can add your book like this

POST library/books/ISBN-10:1449358543
{
  "type": "Paperback",
  "pages": 724,
  "Publisher": "O'Reilly Media; 1 edition (Feb. 7 2015)",
  "language": "English",
  "tag": "Elasticsearch: The Definitive Guide Paperback – Feb 7 2015\nby Clinton Gormley (Author), Zachary Tong (Author)",
  "desc": "Whether you need full-text search or real-time analytics of structured data—or both—the Elasticsearch distributed search engine is an ideal way to put your data to work. This practical guide not only shows you how to search, analyze, and explore data with Elasticsearch, but also helps you deal with the complexities of human language, geolocation, and relationships.\nIf you’re a newcomer to both search and distributed systems, you’ll quickly learn how to integrate Elasticsearch into your application. More experienced users will pick up lots of advanced techniques. Throughout the book, you’ll follow a problem-based approach to learn why, when, and how to use Elasticsearch features.\nUnderstand how Elasticsearch interprets data in your documents Index and query your data to take advantage of search concepts such as relevance and word proximity Handle human language through the effective use of analyzers and queries Summarize and group data to show overall trends, with aggregations and analytics Use geo-points and geo-shapes—Elasticsearch’s approaches to geolocation Model your data to take advantage of Elasticsearch’s horizontal scalability Learn how to configure and monitor your cluster in production"
}

You can search documents by any field

POST library/books/_search
{
  "query": {
    "term": {
      "language": {
        "value": "english"
      }
    }
  }
}

Or any fields combination

POST library/books/_search
{
  "query": {
    "bool": {
      "should": [
        {"term": {
          "language": {
            "value": "english"
          }
        }},
        {"term": {
          "type": {
            "value": "paperback"
          }
        }}
      ]
    }
  }
}

Upvotes: 4

Related Questions