> For the complete documentation index, see [llms.txt](https://docs.hyper-space.io/hyperspace-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hyper-space.io/hyperspace-docs/flows/setting-up/building-and-running-queries/building-a-lexical-search-query.md).

# Building a Lexical Search Query

Lexical Search, or Classic Search, is a fundamental approach to retrieve information based on keyword, integer, float, date etc. value matching. This search operates by assessing the similarity of a collection documents to a query document. It then selects the documents with the top scores and return their id's to the user.&#x20;

## Running the Lexical (Classic) Search Query in DSL Syntax

{% 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" %}

<pre class="language-javascript" data-line-numbers><code class="lang-javascript">let size = 10;
let query = {
<strong>    "query": {
</strong>        "bool": {
            "must": [
                {"term": {"name": "John"}}
            ]
        }
    }
}
await hyperspaceClient.dslSearch(collectionName, size, query)
</code></pre>

{% endtab %}
{% endtabs %}

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

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

```python
query = {
  "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
    }
  }
}
```

{% endcode %}
{% endtab %}

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

```java
String queryJson =" { " + 
"    \"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 " + 
"    } " + 
"  } " + 
"} " + 
JsonObject query = JsonParser.parseString(queryJson).getAsJsonObject();
Object response = client.dslSearch(collectionName, 10, query));
```

{% endcode %}
{% endtab %}

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

```javascript
let query = {
  "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
    }
  }
};
```

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