Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
ElasticSearch Blueprints

You're reading from   ElasticSearch Blueprints A practical project-based guide to generating compelling search solutions using the dynamic and powerful features of Elasticsearch

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher Packt
ISBN-13 9781783984923
Length 192 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Google-like Web Search 2. Building Your Own E-Commerce Solution FREE CHAPTER 3. Relevancy and Scoring 4. Managing Relational Content 5. Analytics Using Elasticsearch 6. Improving the Search Experience 7. Spicing Up a Search Using Geo 8. Handling Time-based Data Index

Using phrase query to search

We added some documents to the index that we created. Now, let's examine some ways to query our data. Elasticsearch provides many types of queries to query our indexed documents. Of all the ones available, the simple query string query is a great place to start. The main advantage of this query is that it will never throw an exception. Also, a simple query string query discards the invalid parts of the query.

It mostly covers what is expected from most of the search engines. It takes OR of all the terms present in the query text, though we can change this behavior to AND. Also, it recognizes all Boolean keywords in the query text and performs the search accordingly. For details, you can look through http://lucene.apache.org/core/2_9_4/queryparsersyntax.html.

To query an Elasticsearch index, we must create a JSON query. A simple JSON query is shown here:

{
"query": {
    "simple_query_string": {
      "query": "sms",
      "fields": [
        "_all"
      ]
    }
  }

The screenshot of how a query is passed and the response is received in the head UI is shown as follows:

Using phrase query to search

The explanation of the field's result is as follows:

  • took: This is the time taken by Elasticsearch in milliseconds to perform the search on the index.
  • hits: This array contains the records of the first 10 documents that matched.
  • _id: This is a unique ID that refers to that document.
  • _score: This is a number that determines how closely the search parameter you provided matched this particular result.
  • _source: When we give Elasticsearch a feed to document, it stores the original feed separately. On a document match, we receive this stored document as the _source field.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image