# Search

## Search API

Use the Search API to query the indexed products. The Search API is also used to apply any sorts or filters.

<mark style="color:green;">`POST`</mark> `https://api.neuralens.ai/search/query`

### Request Headers

| Header                     | Value                       |
| -------------------------- | --------------------------- |
| X-Neuralens-API-Key        | Bearer YOUR\_API\_KEY\_HERE |
| X-Neuralens-Application-ID | YOUR\_APPLICATION\_ID       |

### Request Params

<table><thead><tr><th width="138">Param</th><th>Value</th></tr></thead><tbody><tr><td>partition</td><td>Partition field's value (required in case partitioning is done)</td></tr></tbody></table>

Let's say `partition` is enabled on field "continent", then when sending request for the continent "asia", partition will be `asia`

### Request Body&#x20;

```json
{
    "query": "shirt",
    "offset": 0,
    "limit": 20,
    "filters": [
        {
            "field": "brand",
            "values": ["H&M", "Lacoste", "Nike"]
        }
    ],
    "fields": ["id", "productUrl", "title", "images"],
    "sorts": [
        {
            "field": "inStock",
            "order": "desc"
        },
        {
            "field": "salePrice",
            "order": "asc"
        }
    ],
    "sortOrder": "desc",
    "analytics": {
        "userId": "8769"
    }
}
```

`query` The search query text

`offset, limit` For pagination. offset is the index at which the requested page starts, limit is the number of results required on the page

`filters` Filters to be applied on the results

`sorts` Sorts applied by the user, if there are are more than one sort, next sort will only be used in case of tiebreaker from previous ones

`fields` Fields required in the search response

`analytics` Metadat required for performance tuning and personalisation

### Response

```json
{
    "qid": "59f7e4d1-1364-4903-9f92-8691af26d7e2",
    "results": [    
        {
            "id": "AD176",
            "title": "Printed T-shirt",
            "images": ["https://cdn.example.com/123", "https://cdn.example.com/789"],
            "productUrl": "https://example.com/product/AD176"
        },
        {
            ...
        }
    ],
    "filters": [
        {
            "field": "size",
            "label": "Size",
            "values": [
                {"value": "S", "count": 10, "is_applied": false}, 
                {"value": "M", "count": 10, "is_applied": false}, 
                {"value": "L", "count": 10, "is_applied": false},  
            ],
        },
        ...
    ],
    "sorts": [
        {
            "field": "relevance",
            "order": "desc",
            "label": "Relevance",
            "is_applied": true
        },
        {
            "field": "price",
            "order": "asc",
            "label": "Price - Low to High",
            "is_applied": false
        },
        ...
    ]
    "pagination": {
        "total": 45,
        "current_offset": 0,
        "next_offset": 20
    }
}
```

`qid` Unique id of the query

`results` List of search results

`filters` List of applicable filters, and their values. `is_applied` tells whether the current filter is already applied.

`sorts` List of applicable sorts, and their values. `is_applied` tells whether the current sort is applied.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neuralens.ai/reference/api-reference/search.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
