How querying works

Important: A newer version of this software with updated documentation is available. Visit the Couchbase Developer Portal for more information.

Using Couchbase Server with Elasticsearch, users can actually perform searches based on rich text content within a document, such as information in text descriptions. Imagine a user wants to find a beer that has a nice fruity flavor reminiscent of blueberries. Your application can take in a query string as a web form parameter and send the query to Elasticsearch as JSON containing the term ‘blueberry’. Your application would send a query via HTTP to Elasticsearch as follows:

GET http://127.0.0.1:9200/beer-sample/_search?q=blueberry

Elasticsearch responds by sending the document ID for this beer document in a JSON array. The array will contain elements with document IDs for those documents which match the query parameter:

....
"hits" : [{
    ....
    "_source": {
        "meta" : {
            "id": "110ac410b16h"
            .....
        }
    }
}....

For purposes of brevity we omit other details from the JSON response. The “id” field in the response is the ID you use to retrieve a document from Couchbase Server. With this ID, we can retrieve a document from Couchbase for the beer document with a blueberry aroma in the text description:

{
    "name" : "Wild Blueberry Lager",
    "abv" : 8,
    "brewery_id" : "110f01",
    "description" : "....blueberry aroma....",
    "style" : "Belgian Fruity Lambic"
    ....
}

With Elasticsearch you can use text search queries, you can also provide logic and regular expressions to describe search criterion. The rest of this guide will show you how you can implement full text search using Couchbase Server, the Couchbase Plug-in and Elasticsearch.