Efficient Full Text Search With Vespa: Basic Start

cal 1 Mar 2024

Goal

Set up and deploy Vespa application. Index documents and execute search queries.

Prerequisites

Before diving into Vespa’s full text search capabilities, ensure you have the following:

Setting Up Vespa Container

Start by running a Vespa container using Docker:

docker run -d -p 8080:8080 -p 19071:19071 vespaengine/vespa:8.296.15

Deploy Vespa Application Package (VAP)

Navigate to the downloaded VAP directory. The crucial components here are book.sd - the schema of the search entity (book). And book_v1.xml - the search query template (profile) based on three fields: title, tags, and description.

Deploy the VAP:

vespa deploy book

Feeding Documents

Once the VAP is deployed and running, feed documents using:

vespa feed book/ext/docs.json

Search Documents

Execute search requests using curl:

curl http://localhost:8080/search/ \
--header 'Content-Type: application/json' \
--data '{
    "queryProfile": "book_v1",
    "search_term": "Scott Fitzgerald",
    "query_filter": "AND year > 1800"
}'

or

curl http://localhost:8080/search/ \
--header 'Content-Type: application/json' \
--data '{
    "queryProfile": "book_v1",
    "search_term": "Diamond",
    "query_filter": "AND year > 1800"
}'

Both requests should return Scott Fitzgerald’s "The Diamond as Big as the Ritz" book:

{
    "root": {
        "id": "toplevel",
        "relevance": 1.0,
        "fields": {
            "totalCount": 1
        },
        "coverage": {
            "coverage": 100,
            "documents": 6,
            "full": true,
            "nodes": 1,
            "results": 1,
            "resultsFull": 1
        },
        "children": [
            {
                "id": "index:content/0/65d8db90af64f0e5c9b77e55",
                "relevance": 0.08409605150787772,
                "source": "content",
                "fields": {
                    "sddocname": "book",
                    "title": "The Diamond as Big as the Ritz",
                    "author": "Scott Fitzgerald",
                    "description": "Scott Fitzgerald's extraordinary fantasy was written...",
                    "tags": [
                        "science"
                    ],
                    "year": 1921
                }
            }
        ]
    }
}

Note: By default, the returned documents are ordered by the relevance field.

Summary

Congratulations on setting up Vespa efficiently! In just a few steps, you’ve deployed the Vespa engine, indexed documents, and executed search requests seamlessly.

Next Steps

Explore Customizing Ranking to enhance search results further.