concept Elasticsearch in category elasticsearch

appears as: Elasticsearch, Elasticsearch
Relevant Search: With applications for Solr and Elasticsearch

This is an excerpt from Manning's book Relevant Search: With applications for Solr and Elasticsearch.

Getting a search engine to behave can be maddening. Whether you’re just getting started with Solr or Elasticsearch, or you have years of experience, you’ve likely struggled with low-quality search results. Out-of-the-box settings haven’t met your needs, and you’ve fought to deliver even marginally relevant search results.

Now with some interesting data loaded, you’ll index these documents into Elasticsearch. Elasticsearch has several ways to index documents. You’ll predominantly use the bulk index API that allows you to efficiently index multiple documents in one HTTP request. Don’t worry too deeply about the ins and outs of the bulk index APIs; knowing the indexing APIs in any more depth than what’s presented here isn’t key for this book. What’s crucial for relevance is having an ability to re-create the index with new analysis and index settings. Once it’s re-created, you’ll need to reprocess documents against the updated settings.

That being said, let’s create a function, reindex, that you can refer to. The reindex function takes settings and the movieDict dictionary returned from extract, re-creates the Elasticsearch index, and indexes the data into Elasticsearch.

Listing 3.3. Indexing with Elasticsearch’s bulk API—reindex

In reindex, you first interact with Elasticsearch by re-creating a tmdb index for your data with passed-in settings. Creating an index is synonymous with creating a database in a relational database system. The index will contain your documents and other pieces of search configuration for tmdb content. You’ll work with the /tmdb Elasticsearch HTTP endpoint when working with the tmdb index as a whole.

Luckily, despite superficial differences, Solr and Elasticsearch are very close in functionality. The information you’ll learn in this book applies to either. Use this book as you’d use an algorithms book that happens to use C for its examples. We happen to use Elasticsearch. You can easily implement algorithms in any programming language. You can implement the relevance strategies here in either search engine.

If you’re a Solr developer, fear not: our basic use of Elasticsearch APIs should feel familiar. We’ll give you just enough of an explanation about what’s happening with Elasticsearch that even a smidgen of familiarity with either search engine should help you feel at home. Further, in this chapter, as we lay the foundation for several basics, we sprinkle hints for the Solr reader. We also provide appendix B to help map features between the two search engines.

It’s also important to note that this book isn’t about Elasticsearch. We focus on features related to relevance, completely ignoring other features and concerns when using a search engine: analytics, ingesting your data, scaling, and performance. If you have absolutely no familiarity with Solr or Elasticsearch, there are excellent books and tutorials on both that we encourage you to read before diving into this book.

Listing A.6. Index to Elasticsearch
movieIds = movieList() movieDict = extract(movieIds) reindex(movieDict=movieDict)