> 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/queries/dsl-query-interface/candidate-generation-and-metadata-filtering.md).

# Candidate Generation and Metadata Filtering

Candidate filtering is the process of narrowing down a set of potential documents that might be relevant to a search query before the scoring phase. You can filter candidates using the following methods –

* Exact Match Between Keywords
* Window Match Between Dates
* Match Between Geo Coordinates

## Term Match

A Term query searches for documents that contain a specific, exact value in a particular field. It is designed for exact matches and is commonly used for fields that are not analyzed, such as keyword fields.

You can match either keywords or lists of keywords. For individual keywords, a match requires an exact match between the keywords. For lists of keywords, a match requires an exact match between any two keywords in the two lists.

**Example 1**

In the following example, candidates must include the field 'Continent' and contain the value "Asia" in the 'Continent' field –

{% code lineNumbers="true" %}

```json
{
  "query": {
    "term": {
      "Continent": "Asia"
    }
  }
}

```

{% endcode %}

**Example 2**

In the following example, candidates must include the field 'Continent' with any of the following values - "Asia", "Europe", "Africa" in the field 'Continent' –

{% code lineNumbers="true" %}

```json
{
  "query": {
    "term": {
      "Continent": ["Asia", "Europe", "Africa"]
    }
  }
}

```

{% endcode %}

## Range Match

The `range` query filters documents based on a specified range of values within a given field. It can be used for numeric and date fields. The Range query uses the following terms –

* "gte" – The document's value must be greater than or equal to the provided values.
* "gt" – The document's value must be greater than the provided values.
* "lte" – The document's value must be smaller than or equal to the provided values.
* "lt" – The document's value must be smaller than the provided values.

**Example 1**

The following example requires candidates to have a field named "date" with values that are greater than or equal to "2023-01-01" and smaller than or equal to "2023-12-31".

{% code lineNumbers="true" %}

```python
{
  "query": {
    "range": {
      "date": {
        "gte": "2023-01-01",
        "lte": "2023-12-31"
      }
    }
  }
}
```

{% endcode %}

**Example 2**

The above example requires candidates to have a field named "DateTime" with values greater than or equal to "2023-01-01T08:00:00" and smaller than "2023-01-01T17:30:00."

{% code lineNumbers="true" %}

```python
{
  "query": {
    "range": {
      "datetime": {
        "gte": "2023-01-01T08:00:00",
        "lt": "2023-01-01T17:30:00""
      }
    }
  }
}
```

{% endcode %}

**Example 3**

The above example requires candidates to have a field named "price" with values greater than "10" and smaller or equal to "30".

{% code lineNumbers="true" %}

```json
{
  "query": {
    "range": {
      "price": {
        "gt": 10,
        "lte": 30
      }
    }
  }
}
```

{% endcode %}

## Geo Coordinates Match

The geo\_distance query performs proximity searches based on geographic coordinates to find documents that are within a specified distance from a given geographical point. The query uses the following terms –

* <mark style="color:purple;">`"distance"`</mark>– Specifies the distance within which to search. This can be expressed in units like "km" (kilometers), "mi" (miles), "m" (meters), "yd" (yards) and "ft" (feet).
* <mark style="color:purple;">"point"</mark> – Specifies the point around which to center, in geocoordinates "lat", or "lon".

**Example**

In the following example, the query is searching for documents with a field named `"point"`, whose value is within a 10-kilometer radius of the coordinates (31.19, -44.41)

{% code lineNumbers="true" %}

```json
{
  "query": {
    "geo_distance": {
      "distance": "10km",
      "point": {
        "lat": 31.19,
        "lon": -44.41
      }
    }
  }
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.hyper-space.io/hyperspace-docs/flows/queries/dsl-query-interface/candidate-generation-and-metadata-filtering.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
