• [+] expand all

Vespa Query Language - YQL

Vespa accepts unstructured human input and structured queries for application logic separately, then combines them into a single data structure for executing. Human input is parsed heuristically, see Query API input. Application logic is expressed in YQL, use this guide for examples - also see the YQL reference.

Live query examples

The following are live YQL examples:

select * from doc where true

Selection: Select all documents from the "doc" source. This is the easiest way to count all documents in a source.

select * from doc where title contains "ranking"

Filtering: Find all documents with "ranking" in the "title" field.

select * from doc where default contains "ranking"

Filtering: Find all documents with "ranking" in the "default" fieldset.

select * from doc where true order by term_count desc

Ordering: Order by number of terms in the document, descending.

select * from doc where true limit 15 offset 5

Pagination: Select all documents, return hits 6-15.

select * from doc where true limit 0 | all( group( fixedwidth(term_count,100) ) each( output( avg(term_count) ) ) )

Grouping:

  • Select all documents from the "doc" source.
  • Group by term count in buckets of 100, display average term count per bucket.
  • Note "limit 0": This will return 0 regular hits, hence only the grouping result.

Find more grouping examples.

select * from doc where last_updated > 1646167144

Numeric: Select documents with attribute "last_updated" > 1646167144.

select * from doc where default contains phrase("question","answering")

Phrase: Select documents with the phrase "question answering".

select * from doc where true timeout 100

Timeout: Time out query execution after 100 ms. This will be default return hits found so far, see ranking.softtimeout.

select * from doc where namespace matches "op.*"

Regular expressions: Select documents matching the regular expression in the "namespace" attribute field.

select * from doc where has_full_text = false

Boolean: Select documents with boolean attribute field "has_full_text" = false.

Command-line queries

To run a query from the command-line, set the query as the yql parameter like:

$ curl --data-urlencode 'yql=select * from doc where true' \
  https://doc-search.vespa.oath.cloud/search/

Alternatively, use the Vespa CLI:

$ vespa query 'select * from doc where true'

Query examples

Map

$ curl -H "Content-Type: application/json" \
    --data '{"yql" : "select * from sources * where my_map contains sameElement(key contains \"Coldplay\", weight > 10);"}' \
    http://localhost:8080/search/

field my_map type map<string, int> {
    indexing: summary
    struct-field key   { indexing: attribute }
    struct-field value { indexing: attribute }
}