Request
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
Array of Strings |
Yes (either this or siteId) |
Sites to be used for searching |
|
|
String |
Yes(either this or siteIds) |
Site to be used for searching |
|
|
String |
No |
Query for documents using Advanced Query Language . Defaults to match all documents |
|
|
String |
No |
Filter for documents using Advanced Query Language without affecting scoring/ranking |
|
|
Number |
No |
Limit the number of matches. Must be an integer from 0 to 1000. Default value is 10. |
|
|
Number |
No |
Skip a number of documents when returning matches. Must be a positive number. Default value is 0. Value of start + count must be at most 10000. |
|
|
Array of Strings |
No |
Only return a specific list of document fields |
|
|
Array of Facet objects |
No |
Configure facets for the search |
|
|
Array of Highlight objects |
No |
Configure highlights for fields |
|
|
Array of Sort objects |
No |
Configure the sort order of the result |
|
|
String |
No |
The logged query string that will be used in /reports/search |
|
|
String |
No |
The rank model to use. A rank model affects how the score of a document is computed, and thus should be used with a |
|
|
Spellcheck object |
No |
Did-you-mean spellchecking. |
Facet
The main purpose of using facets is to surface relevant metadata for users as well as enable further narrowing of results by restricting the data returned to only those that match specific metadata values (e.g. Department = Books). You may know this feature also as Drill Down, Navigator or Faceted Browsing.
Facets are calculated for the current query only. To return facets across the entire index, simply execute a search matching all documents by not specifying query or filter in the request, with facets set to the facets for which you wish to return statistics. Also, if you are interested only in the facets, remember to specify that no results need to be retrieved by setting count to 0.
Facets can be an expensive operation, as they are calculated on the entire result set to provide exact frequency counts, and may affect query response time.
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The type of the facet. Either |
|
|
String |
Yes |
The name of the field |
|
|
Number |
For |
The maximum number of facets |
|
|
Number |
For |
Only include results over a given threshold |
|
|
Number |
For |
The latitude/longitude of the origin point, which will be used when calculating the distance to documents. The longitude must be between -180 and 180 (where negative values are west). The latitude must be between -90 and 90 (negative values are south) |
|
|
Number |
||
|
|
String |
For |
The distance unit used in the buckets |
|
|
Array of Bucket objects |
For range facets |
Configure bucket ranges to be used when building facets |
Bucket
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
Number or String |
No* |
Set the boundaries for the range. The type must be a number for time specification for |
|
|
Number or String |
No* |
* At least one of start and stop must be set.
Spellcheck
Request a did-you-mean spellchecking of a provided query.
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The query string to be spellchecked. Should typically be the raw query a user enters in a search box. |
Highlight
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The name of the field |
|
|
String |
Yes |
Inserted at the beginning of the highlighted section |
|
|
String |
Yes |
Inserted at the end of the highlighted section |
|
|
Number |
No |
Limit the number of characters of the highlighted section |
Sort
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The type of the sort. Either |
|
|
String |
Yes |
The sort order. Either |
|
|
String |
For |
The name of the field. Not supported for some free text fields (e.g. |
|
|
Number |
For |
The latitude/longitude of the origin point, which will be used when calculating the distance to documents. The longitude must be between -180 and 180 (where negative values are west). The latitude must be between -90 and 90 (negative values are south) |
Response
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
Number |
Yes |
The total number of matching documents, independent of facets. |
|
|
Array of Match objects |
Yes |
The returned matches |
|
|
Array of Facet objects |
No |
The facets, if requested, returned in the same order as the request |
|
|
Array of Spellcheck result objects |
No |
The possible spellcheck corrections, if requested. Possibly empty if no relevant corrections are found. For did-you-mean spellchecking (the type currently supported by this API), there will not be more than a single result. |
Match
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The document ID |
|
|
String |
Yes |
The siteId where the document was found |
|
|
Number |
No |
The score for the document, if score sort was used |
|
|
Array of Field objects |
Yes |
The document fields |
|
|
Array of Highlight objects |
No |
The highlights for the document, if requested |
|
|
Explanation object |
No |
Will only be set when search is made with |
Explanation
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
Final score of the match. |
|
|
Any |
No |
The score before the rank algorithm is applied. Only included if rank is provided. |
|
|
Array of Object |
Yes |
Contains a |
{
"explanation": {
"score": 30.0,
"scoreBeforeRank": 1.0,
"fields": [
{
"field": "xxx-tag",
"term": "sports",
"score": 0.25
},
{
"field": "xxx-tag",
"term": "illustrated",
"score": 0.25
},
{
"field": "title",
"term": "sports",
"score": 0.5
}
]
}
}
Field
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The field's name |
|
|
Any |
Yes |
The field's value |
Highlight
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The name of the field |
|
|
String |
Yes |
The content of the field with highlight |
Facet
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
Array of Bucket objects |
Yes |
The list of buckets for the facet. Buckets are returned in the requested order. |
Bucket
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The label of the bucket. For |
|
|
Number |
Yes |
The number of documents in the bucket |
Spellcheck
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The term that is spellchecked. For did-you-mean spellchecking (the type currently supported by this API), the term is always the entire query. |
|
|
Array of suggestion objects |
Yes |
Non-empty list of did-you-mean spellcheck suggestions for the given term. Ordered by relevancy, with the most relevant suggestion first. |
Suggestion
|
Name |
Type |
Required |
Description |
|---|---|---|---|
|
|
String |
Yes |
The spellcheck suggestion. |
Basic example
cx.py /document/search '{"siteIds":["99999999","8888888"],"query":"query(\"2016 NFL playoffs schedule\")"}'
{
"totalCount": 5,
"matches": [
{
"id": "abeddbf210aa0160c0418ff2c3c3b4895459e1a7",
"siteId": "9999999999",
"score": 1.1385926,
"fields": [
{
"field": "author",
"value": "associated press"
},
{
"field": "body",
"value": [
"Wild-card Playoffs",
:
:
Advanced Query Language
One of the main advantages of a query language is the flexibility it provides for you to construct complex search requests. Understanding the Advanced Query Language well allows you to construct queries containing parameters such as:
-
Single words or phrases.
-
Filters for textual metadata.
-
Range filters for numeric data, including dates.
-
Boosting different parts of the query differently against the target documents.
-
Nested boolean logic combining all of the above.
Handling special characters in user queries
Most characters are handled literally when passed through the query parameter, yet there are a few exceptions listed in this table below. When developing your search application, you must anticipate and properly handle the special characters listed below, or your queries will fail.
|
Character |
Description |
|---|---|
|
|
A backslash is used as the escape character for the below characters. Hence it must itself be escaped if present in a user query. To escape the backslash itself, it must be passed like this |
|
* |
Wildcard means all content. If you want to search |
|
" |
Any string passed as part of the query is quoted by double quotation (
|
Query operator
The query operator is used to specify multiple query fragments that can contain anything from a very single keyword targeting all searchable content to complex phrases targeting different parts of the document with different weight, giving different parts of the query different weight as well. Matching will be performed against normalized content (i.e. case/accent insensitive, depending on the index language). If exact match on a field value is needed, use the filter operator.
The query operator has the following syntax:
query(<field>^<boost>:"<query content>", token-op=<token operator>)
The following table provides more details on each of the available parameters listed above:
|
Parameter |
Default |
Meaning |
Examples |
|---|---|---|---|
|
|
_all |
This parameter defines what parts of the content should checked when looking for the <query content> specified. If this parameter is omitted, it will default to the reserved value |
query("ford") query(title:"ford") query(_all,body,description:"ford") |
|
|
1 |
Defines how much weight should be applied to this particular part of the query, and therefore can be used to define which fields are more important. A negative value will down-boost a field, making it less important. When defining multiple fields as mentioned above, each field get their own boost. |
query(name^2:"mustang") query(title^5,description^2:"mustang") |
|
|
N/A |
One or more words When passing multiple words, by default all of them must be found (see token operator below). The special value |
query("market research") query("*") |
|
|
and |
|
query("classic dark green",token-op=phrase) |
Filter operator
The filter operator have a similar format and use as the query operator. However, while a query condition will both affect recall (which documents are returned) and relevancy (which order the documents come back), a filter condition will only affect recall. In other words, a filter will not affect score of hits.
All values are strongly typed (i.e. filtering for a string will not match on a number field, event though the string looks like a number). The following types are supported:
|
Type |
Description |
Example |
|---|---|---|
|
|
A string for filtering on exact string values without any normalization |
filter(string-field:"example") filter(string-field:["foo", "bar", "baz"]) |
|
|
Integer or float |
filter(number-field < 42) filter(number-field > 13.37) |
|
|
A time/date formatted according to Traffic time specification . Note that time is queried with a resolution of seconds, even if millisecond time specifications are allowed. |
filter(time-field > time("-24h")) filter(time-field:range[time("2013-01-01T00:00:00Z"), time("2014-01-11T00:00:00Z")]) |
|
|
A string for exact lookup in a field of type set |
filter(set-field:contains("foo")) |
Value filter
A value filter only works on exact values and no matching against normalized content will happen. When filtering on multiple values, all values must be of the same type. Documents that contain any one of the specified values will match. It has the following format:
filter(<field>:<value>)
filter(<field>:[<value1>,...,<valueN>])
Open range filter
The open range filters have the following format:
filter(<field><operator><value>)
Where these are the valid options for the operator parameter:
|
Operator |
Description |
|---|---|
|
|
Greater than |
|
|
Greater than or equal to |
|
|
Less than |
|
|
Less than or equal to |
Example - combining filter with relative time and fielded query
cx.py /document/search '{"siteId":"1234","resultFields":["url","timestamp","recs-publishtime","xxx-tag"],"filter":"filter(recs-publishtime > time(\"-300h\"))","query":"query(xxx-tag:\"nyhetsvarsel\")"}'
Closed range filter
The closed range filters have the following format:
filter(<field>:range<left operator><value1>,<value2><right operator>)
Where these are the valid options for the operator parameter:
|
Operator |
Description |
|---|---|
|
|
Greater than |
|
|
Greater than or equal to |
|
|
Less than |
|
|
Less than or equal to |
Geo box filter
When filtering for geo locations, it's often useful to find all points inside a bounding box. This can be accomplished using a geo bounding box filter, which has much better performance than the naive approach of using range filters. The geo bounding box filter has the following format:
filter(<field>:geobox[[<top left longitude>,<top left latitude>],[<bottom right longitude>,<bottom right latitude>]])
Contains filter
Fields of type "set" (multi value fields) can be filtered on by using the "contains" operator.
filter(<field>:contains(<value>))
Boolean Operators combining "query" or "filter"
The Boolean operators allow you to combine multiple query or filter operators to build complex search requests.
|
Operator |
Description |
|---|---|
|
|
conditions are mandatory |
|
|
condition after this operator must not be matched |
|
|
conditions are optional |
# query examples
"query":"NOT query(...)"
"query":"NOT query(...) AND query(...)"
# filter examples
"filter":"filter(...) AND filter(...)"
"filter":"filter(...) OR filter(...)"