This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Search Elasticsearch using Query Parameters

    Will ButtonWill Button

    Simple searches can be done using query parameters, also known as “Search Lite” by Elasticsearch. You will learn how to perform query parameter searches in this lesson and also discover the upper limits of its usability in this lesson.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:01 I'm going to do curl again on localhost. This time, I'm going to specify to search all indices of the type "episode." Here's my search endpoint. I'm going to specify my parameter with a q=, and then I want to look for the title being set to Homer. Again, I'll pipe that to jQ.

    00:29 In our results here, it goes to Elasticsearch and finds all documents of type "episode" containing Homer in the title field. If I scroll back through here, you can see the title here is Homer.

    00:42 Here's another one titled Homer, and so on. If I go back to the beginning of my search results, it tells me that there were a total of 43 documents in my cluster that have Homer in the title.

    00:56 Let's search for all documents in the cluster that have Homer in the title from Season 5. We'll hit our server again, localhost on port 9200. We're going to go to all indices, hit the episode type using the search endpoint.

    01:16 Now, watch this. I've got my q=%2b, which is the URL-encoded version of the plus sign. I'm going to specify title, and then %3a, which is my colon, specify my search term, which is Homer.

    01:37 Now I'll do a regular +, and then another %2b to specify the URL encoded +, type the word season, and then a colon again, which is %3a, and then number 5 to specify Season 5.

    01:55 Again, we'll pipe that to jQ, run that. If I did it right, here's Homer from Season 5. This one's Homer from Season 5. It looks like they're all Homer from Season 5. If we go to the top, there were a total of six documents that matched that query.

    02:13 Let's do one more. Let's find any episode with Homer or Bart in the title and an IMDb rating over eight. We're going to do curl again, localhost, port 9200, and then we'll specify...

    02:27 This time we're going to do an underscore search, hit the search endpoint right away, which searches everything in the cluster, throw our parameters in there with q=, and then, again, we'll do %2b for our + sign, our title, and then we're going to do a %3a for our colon, and then %28, which is a parenthesis.

    02:52 We'll do Homer%2b for +, followed by the word Bart because we want to search for Bart as well, %29 to close our parenthesis, +%2b for another + sign, and then our field IMDb rating, which is IMDb_rating, and then a colon, which is %3a, then >%3e8, and then we'll pipe that to jQ.

    03:28 When that comes back, we have "Radio Bart," which has an IMDb rating of 8.5, "Bart After Dark" with 8.2, "Homer the Bad Man" with an IMDb rating of 9. That worked.

    03:43 When we scroll back up and look at this, that's kind of less than usable. This is certainly not anything that you would turn over to your end users and try to teach them how to URL-encode percent and plus signs and expect them to deliver, or expect them to be functional with this.

    04:04 It's a good way for you to troubleshoot or test your query whenever you're just working from the command line, but for delivering a polished application to your users, Elasticsearch has the Query DSL language that we'll jump into in the next lesson.

    Discuss

    Discuss