# dsl\_search

The function dsl\_search`(query_schema, size, function_name, collection_name)` runs search queries Iin DSL syntaxt inside a collection.

**Input**

* <mark style="color:purple;">query\_schema</mark> – the DLS query object.
* <mark style="color:purple;">size</mark> – Specifies the number of results to return.
* <mark style="color:purple;">function\_name</mark> – Specifies the scoring function to be used in the Classic Search query, as described in Step 1, Creating the Scoring Function.
* <mark style="color:purple;">collection\_name</mark> – Specifies the Collection in which to search.
* <mark style="color:purple;">fields (optional)</mark> – Specifies the document fields to be returned with each result.

**Example**&#x20;

{% tabs %}
{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
query = {
        "query": {
            "bool": {
                "must": [
                    {"term": {"name": "John"}}
                ]
            }
        }
    }
results = hyperspace_client.dsl_search(query,
                                   size=10,                 
                                   collection_name=collection_name)
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
String queryJson =  "{" +
                    "  \"query\": {" +
                    "    \"bool\": {" +
                    "      \"must\": [" +
                    "        {" +
                    "          \"term\":{" +
                    "            \"name\":\"John\"" +
                    "           }" +
                    "        }" +
                    "      ]" +
                    "    }" +
                    "  }" +
                    "}";
JsonObject query = JsonParser.parseString(queryJson).getAsJsonObject();
Object response = client.dslSearch(collectionName, 10, query));
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```javascript
const size = 10;
const query = {
        "query": {
            "bool": {
                "must": [
                    {"term": {"name": "John"}}
                ]
            }
        }
};
await hyperspaceClient.search(collectionName, size, query);
```

{% endcode %}
{% endtab %}
{% endtabs %}

Where <mark style="color:purple;">query\_string</mark> is your query logic, see example below.

{% code lineNumbers="true" %}

```
{
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "genres": "genres_value"
              }
            },
            {
              "term": {
                "adult": "adult_value"
              }
            },
            {
              "bool": {
                "must_not": [
                  {
                    "term": {
                      "title": "title_value"
                    }
                  }
                ]
              }
            }
          ],
          "should": [
            {
              "range": {
                "rating": {
                  "gt": 7.0
                }
              }
            }
          ]
        }
      },
      "boost_mode": "multiply",
      "boost": 2.0
    }
  }
}Response
```

{% endcode %}

A list of candidates, as shown in the example below

{ "candidates": 1, "similarity": \[ { "document\_id": "29", "score": 10.0, "fields": { "FirstSeenTime": 1506116398, "City": "Jakarta" } } ], "took\_ms": 33.625 }


---

# 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.hyper-space.io/hyperspace-docs/api-documentation/hyperspace-client/dsl_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.
