Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
157 lines (152 sloc) 4.63 KB
---
# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
title: "Vespa Query Language - YQL"
---
<script>
function replace(encodedText) {
var body_element = document.getElementsByTagName('body')[0];
var selection = window.getSelection();
var newdiv = document.createElement('div');
body_element.appendChild(newdiv);
newdiv.innerHTML = encodedText;
newdiv.style.position='absolute';
newdiv.style.left='-99999px';
selection.selectAllChildren(newdiv);
window.setTimeout(function() {
body_element.removeChild(newdiv);
},0);
}
function init() {
var elements = document.getElementsByClassName("urlunencode");
var len = elements.length
for (var i = 0 ; i < len; i++)
{
var original = elements[i].innerHTML;
elements[i].innerHTML = decodeURIComponent(original);
elements[i].getAttributeNode("oncopy").nodeValue = "replace(\""+original+"\");";
}
}
</script>
<p>
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, while application queries are formulated in YQL.
</p><p>
A simple query URL looks like:
<pre>
http://myhost.mydomain.com:8080/search/?yql=select%20%2A%20from%20sources%20%2A%20where%20text%20contains%20%22blues%22%3B
</pre>
In other words, <em>yql</em> contains:
<pre class="urlunencode" oncopy="">
select%20%2A%20from%20sources%20%2A%20where%20text%20contains%20%22blues%22%3B
</pre>
This matches all documents where the field named <em>text</em> contains the word <em>blues</em>.
</p><p>
This document has examples and guides for how to use search operators as found in the
<a href="reference/query-language-reference.html">query language reference</a>.
</p><p>
Example queries:
<table class="table">
<thead></thead><tbody>
<tr>
<th>Ordering</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where default contains \"bad\" order by year desc;"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr>
<th>Grouping</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where default contains \"bad\" | all(group(year) each(output(sum(duration))));"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr>
<th>Pagination</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where default contains \"bad\" limit 2 offset 1;"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr>
<th>Numeric</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where year > 2000;"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr>
<th>Boolean</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where alive = true;"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr>
<th>Phrase</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where artist contains phrase(\"michael\", \"jackson\");"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr>
<th>Timeout</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where default contains \"bad\" timeout 100;"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr>
<th>Regexp</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where title matches \"mado[n]+a\";"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr>
<th>Count</th>
<td>
<pre>
$ curl -H "Content-Type: application/json" \
--data '{"yql" : "select * from sources * where sddocname contains \"music\";"}' \
http://localhost:8080/search/
</pre>
</td>
</tr><tr id="map">
<th>Map</th>
<td>
<pre>
$ 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&lt;string, int&gt; {
indexing: summary
struct-field key { indexing: attribute }
struct-field value { indexing: attribute }
}
</pre>
</td>
</tr>
</tbody>
</table>
</p>
<script>
window.onload=init();
</script>
You can’t perform that action at this time.