Constructing a Basic Search Query

Query constraints can be specified in a number of ways. In the simplest case, a text string is provided and is used as a query constraint to find items that contain the specified text in the default search field. For example, you could specify the query constraint q=read+write to retrieve a list of the items that contain the terms "read" and "write" in any text field:

../search?q=read+write

You can specify additional constraints to search specific fields and use Boolean logic to construct more complex queries. When you search text fields, ASN Search finds all items that contain the search terms anywhere within the specified field. If the field being searched is a literal field, the field contents must exactly match the search string to be returned in results. You can also search uint fields for a particular value or a range of values.

In your search requests, you can also specify how you want ASN Search to rank and return the search hits. Instead of using the default text_relevance scores, you can rank hits alphabetically, or numerically.

When you submit a search request, ASN Search returns a response that specifies how the results were ranked, the match expression that was derived from your query constraints, and a collection of hits that represents the items that match the query constraints. For example:

{
    "rank":"-text_relevance",
    "match-expr":"(label 'read write')",
    "hits":{
        "found":7,
        "start":0,
        "hit":[
            {"id":"s1185834"},
            {"id":"s0076759"},
            {"id":"s0121765"},
            {"id":"s0080684"},
            {"id":"s0086190"},
            {"id":"s0120915"},
            {"id":"s0121766"}]
    },
    "info":{
        "rid":"b7c167f6c2da6d93ecb53d18230cbc27146c9356f9c643ec9dec53e707b9af87f27b24b2f4b636a9",
        "time-ms":4,
        "cpu-time-ms":0
    }
}

found—specifies the total number of items that matched the query.

start—specifies the offset of the first hit included in the response.

id—specifies the unique item ID of an individual hit.

By default, a search response contains the IDs of the first 10 ranked hits. You can retrieve additional information for each hit by specifying which result enabled fields should be included in the response. You can also control how many hits are returned at a time. When you want to page through a large set of matching documents, you can specify the offset of the first hit that you want to retrieve.

For more information, see Controlling How Search Results are Returned.