Search API Reference
editSearch API Reference
editThe Custom search experiences guide provides a conceptual walkthrough of the steps involved in issuing search requests on behalf of users via OAuth.
In this API reference
edit- Search API Overview
- Querying
- Paginating
- Sorting results
- Restricting search fields
- Restricting result fields
- Filtering a query with a value
- Filtering a query with a numerical range
- Filtering a query with geolocation data
- Combining filters
- Configuring value facet options
- Configuring range facet options
- Configuring geolocation facet options
Search API Overview
editPOST http://localhost:3002/api/ws/v1/search
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
The search query |
|
optional |
Provides optional keys of size and current. Specifies the number of results per page and which page the API should return. |
|
optional |
Sort results ASC or DESC for a field |
|
optional |
Fields used for full-text matching |
|
optional |
Fields returned in the JSON response |
|
optional |
Query modifiers used to refine a query |
|
optional |
Faceting configuration |
Search Query
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
A string or number used to find related documents |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "denali"
}'
Pagination
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Provides optional keys of size and current. Specifies the number of results per page and which page the API should return. |
|
optional |
Specifies the number of results per page |
|
optional |
Specifies which page of results to retrieve for the query |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "denali",
"page": {
"size": 1,
"current": 1
}
}'
Sorting
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Sort results ASC or DESC for one or multiple field |
|
field |
Name of the field used for sorting |
|
direction |
ASC or DESC direction for sorting |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "denali",
"sort": [
{ "square_km": "desc" },
{ "date_established": "asc" }
]
}'
Search Fields
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Fields used for full-text matching |
|
field |
Name of the field used for full-text matching |
|
integer |
The relative importance of fields in a query. A higher value represents greater importance for algorithmic scoring. |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "denali",
"search_fields": {
"title": {
"weight": 10
},
"description": {}
}
}'
Result Fields
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Fields returned in the JSON response |
|
field |
Children of the |
|
result type |
Value of the field as originally indexed |
|
result type |
Value of the field with highlighting markup added to visually distinguish where the match occurred |
|
integer |
Character length of the returned value |
|
boolean |
For |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"query": "america",
"result_fields": {
"title": {
"raw": {},
"snippet": {}
},
"description": {
"raw": {
"size": 50
},
"snippet": {
"fallback": true,
"size": 50
}
},
"states": {
"snippet": {
"size": 50
}
}
}
}'
{
"meta": {
...
},
"results": [
{
"title": {
"raw": "American Samoa",
"snippet": "<em>American</em> Samoa"
},
"_meta": {
"source": "custom",
"last_updated": "2020-03-27T20:10:33+00:00",
"content_source_id": "5e7e5d911897c6dbb7e3e72a",
"id": "park_american-samoa",
"score": 6.359234
},
"source": {
"raw": "custom"
},
"states": {
"snippet": "<em>American</em> Samoa"
},
"description": {
"raw": "The southernmost National Park is on three Samoan",
"snippet": "The southernmost National Park is on three Samoan"
},
"last_updated": {
"raw": "2020-03-27T20:10:33+00:00"
},
"content_source_id": {
"raw": "5e7e5d911897c6dbb7e3e72a"
},
"id": {
"raw": "park_american-samoa"
}
},
{
"title": {
"raw": "Denali",
"snippet": null
},
"_meta": {
"source": "custom",
"last_updated": "2020-03-27T20:10:33+00:00",
"content_source_id": "5e7e5d911897c6dbb7e3e72a",
"id": "park_denali",
"score": 6.357545
},
"source": {
"raw": "custom"
},
"states": {
"snippet": null
},
"description": {
"raw": "Centered on Denali, the tallest mountain in North",
"snippet": " <em>America</em>, Denali is serviced by a single road"
},
"last_updated": {
"raw": "2020-03-27T20:10:33+00:00"
},
"content_source_id": {
"raw": "5e7e5d911897c6dbb7e3e72a"
},
"id": {
"raw": "park_denali"
}
},
...
]
}
Value Filters
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Query modifiers used to refine a query |
|
field |
Name of field upon which to apply your filter |
|
field value |
The value upon which to filter. The value must be an exact match, even casing: |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filters": {
"states": ["California", "Washington"]
}
}'
Range Filters
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Query modifiers used to refine a query |
|
field |
Name of field upon which to apply your filter |
|
optional |
Inclusive lower bound of the range. Is required if |
|
optional |
Exclusive upper bound of the range. Is required if |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filters": {
"visitors": {
"from": 100
},
{
"date_established": {
"to": "1900-01-01"
}
}
}
}'
Geo Filters
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Query modifiers used to refine a query |
|
field |
Name of field upon which to apply your filter |
|
required |
The mode of the distribution as a string in "[latitude], [longitude]" format. |
|
required |
The base unit of measurement: |
|
optional |
A number representing the distance unit. Is required if |
|
optional |
Inclusive lower bound of the range. Is required if |
|
optional |
Exclusive upper bound of the range. Is required if |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filters": {
"location": {
"unit": "km",
"center": "47.6062,122.3321",
"distance": 1000
}
}
}'
Combining Filters
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Query modifiers used to refine a query |
|
array |
At least one of the filters must match. This functions as an |
|
array |
All of the filters must match. This functions as an |
|
array |
All of the filters must not match. This functions as a |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filters": {
"all": [
{
"states": ["California", "Washington"]
},
{
"visitors": {
"from": 100
}
},
{
"date_established": {
"to": "1900-01-01"
}
}
],
"any": [
{
"location": {
"unit": "km",
"center": "47.6062,122.3321",
"distance": 1000
}
},
{
"location": {
"unit": "km",
"center": "37.7749,122.4194",
"from": 100,
"to": 10000
}
}
],
"none": {
"world_heritage_site": "true"
}
}
}'
Value Facets
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Faceting configuration |
|
field |
Name of field upon which to apply your facet |
|
required |
Type of facet, in this case |
|
optional |
Name given to facet |
|
optional |
Between 1 and 250, defaults to 10 |
|
optional |
JSON object where the key is either |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"facets": {
"states": {
"type": "value",
"name": "top-five-states",
"sort": { "count": "desc" },
"size": 5
}
}
}'
{
"meta": {
...
},
"results": [
...
],
"facets": {
"states": [
{
"type": "value",
"data": [
{
"value": "Alaska",
"count": 5
},
{
"value": "Utah",
"count": 2
},
{
"value": "Colorado",
"count": 2
},
{
"value": "California",
"count": 2
},
{
"value": "Washington",
"count": 1
}
],
"name": "top-five-states"
}
],
}
}
Range Facets
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Faceting configuration |
|
field |
Name of field upon which to apply your facet |
|
required |
Type of facet, in this case |
|
optional |
Name given to facet |
|
optional |
An array of range objects |
|
optional |
Inclusive lower bound of the range. Is required if |
|
optional |
Exclusive upper bound of the range. Is required if |
|
optional |
Name given to range |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"facets": {
"acres": [
{
"type": "range",
"name": "min-and-max-range",
"ranges": [
{ "from": 1, "to": 10000 },
{ "from": 10000 }
]
}
],
"date_established": {
"type": "range",
"name": "half-century",
"ranges": [
{ "from": "1900-01-01T12:00:00+00:00", "to": "1950-01-01T00:00:00+00:00" }
]
}
}
}'
{
"meta": {
...
},
"results": [
...
],
"facets": {
"acres": [
{
"type": "range",
"data": [
{
"key": "5e7e6cbd1897c6aa79a79c95",
"from": 1,
"to": 10000,
"count": 1
},
{
"key": "5e7e6cbd1897c6aa79a79c96",
"from": 10000,
"count": 19
}
],
"name": "min-and-max-range"
}
],
"date_established": [
{
"type": "range",
"data": [
{
"key": "5e7e6cbd1897c6aa79a79c97",
"from": "1900-01-01T12:00:00.000Z",
"to": "1950-01-01T00:00:00.000Z",
"count": 11
}
],
"name": "half-century"
}
]
}
}
Geolocation Facets
edit
|
required |
Must be included in HTTP authorization headers, is acquired via an OAuth authorization flow. |
|
optional |
Faceting configuration |
|
field |
Name of field upon which to apply your facet |
|
required |
Type of facet, in this case |
|
optional |
Name given to facet |
|
optional |
An array of range objects |
|
optional |
Inclusive lower bound of the range. Is required if |
|
optional |
Exclusive upper bound of the range. Is required if |
|
required |
The mode of the distribution as a string in "[latitude], [longitude]" format. |
|
required |
The base unit of measurement: |
|
optional |
Name given to range |
curl -X POST http://localhost:3002/api/ws/v1/search \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"facets": {
"location": {
"type": "range",
"name": "geo-range-from-san-francisco",
"center": "37.386483, -122.083842",
"unit": "m",
"ranges": [
{ "from": 0, "to": 100000, "name": "Nearby" },
{ "from": 100000, "to": 300000, "name": "A longer drive." },
{ "from": 300000, "name": "Perhaps fly?" }
]
}
}
}'
{
"meta": {
...
},
"results": [
...
],
"facets": {
"location": [
{
"type": "range",
"data": [
{
"key": "Nearby",
"from": 0,
"to": 100000,
"count": 0
},
{
"key": "A longer drive.",
"from": 100000,
"to": 300000,
"count": 0
},
{
"key": "Perhaps fly?",
"from": 300000,
"count": 20
}
],
"name": "geo-range-from-san-francisco"
}
]
}
}