{% extends BASE_TEMPLATE %} {% block title %}API Search Help{% endblock %} {% block breadcrumbs %} {% endblock %} {% block content %}

Search Help

There are two ways to use the search API: URL query parameters and the Elasticsearch query JSON.

URL params search.

Search API uses HTTP GET with filters as URL params.

The fulltext field uses Elasticsearch query_string syntax. DDR field names are searchable via this method. Note: Wildcards at the beginning of a word (eg "*ing") are ignored.

Protip: The search API uses the exact same URL params as the front-facing search UI. Do a search in the UI, then add the API prefix to do an API search. Example:
http://ddrpublic.local/search/?fulltext=minidoka&topics=173&genre=photograph
-> http://ddrpublic.local/api/0.2/search/?fulltext=minidoka&topics=173&genre=photograph

Search query JSON format.

Search queries can also be composed using a subset of the Elasticsearch query syntax and POSTed to the search API URL.

{
    "fulltext": "FULL TEXT SEARCH HERE",
    
    "must": [ ...AND queries... ],
    "should": [ ...OR queries... ],
    "mustnot": [ ...NOT queries... ],
    
    "models": [],
    
    "sort": ["field1", "field2"],
    "limit": 25,
    "offset": 0
}

Subqueries

Subqueries are formatted like Elasticsearch query dicts

{"match": {"fieldname": "value"}}
{"multi_match": {
    "query": "full text search",
    "fields": ["fieldname1", "fieldname2"]
}}
{"terms": {"fieldname": ["value1","value2"]}},
{"range": {"fieldname": {"gt":20, "lte":31}}},
{"exists": {"fieldname": "title"}}
{"missing": {"fieldname": "title"}}

Nested fields

For example, the role field below would be referred to as creators.role.

{
  "creators": [
    {
      "namepart": "Hirabayashi, Gordon",
      "role": "author"
    },
    ...
{% endblock content %}