Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,120 +2,116 @@ import Admonition from '@theme/Admonition';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CodeBlock from '@theme/CodeBlock';
import Panel from "@site/src/components/Panel";
import ContentFrame from "@site/src/components/ContentFrame";

<Admonition type="note" title="">

* To query for documents that contain a particular field,
use extension method `WhereExists()` which is accessible from [DocumentQuery](../../../../querying/document-query/what-is-document-query.mdx).
use the `WhereExists()` extension method which is accessible from [DocumentQuery](../../../../querying/document-query/what-is-document-query.mdx).

* A document that doesn't contain the specified field will be excluded from the query results.

* `WhereExists()` filters documents by field presence, not by how relevant the field's value is.
When you [order results by score](../../../../querying/sorting-query-results/sort-query-results.mdx#order-by-score), `WhereExists()` can contribute to that score.
For how this contribution works with Corax, see [Corax: Scoring](../../../../indexes/search-engine/corax.mdx#scoring).

* In this page:
* [Filter by field name](../../../../client-api/session/querying/how-to-filter-by-field.mdx#filter-by-field-name)
* [Filter by field path](../../../../client-api/session/querying/how-to-filter-by-field.mdx#filter-by-field-path)
* [Syntax](../../../../client-api/session/querying/how-to-filter-by-field.mdx#syntax)
* In this article:
* [Filter by field name](#filter-by-field-name)
* [Filter by field path](#filter-by-field-path)
* [Syntax](#syntax)

</Admonition>
## Filter by field name

<Panel heading="Filter by field name">

<Tabs groupId='languageSyntax'>
<TabItem value="Sync" label="Sync">
<CodeBlock language="csharp">
{`// Only documents that contain field 'FirstName' will be returned
```csharp
// Only documents that contain field 'FirstName' will be returned

List<Employee> results = session
.Advanced
.DocumentQuery<Employee>()
.WhereExists("FirstName")
// Or use lambda expression: .WhereExists(x => x.FirstName)
.ToList();
`}
</CodeBlock>
```
</TabItem>
<TabItem value="Async" label="Async">
<CodeBlock language="csharp">
{`// Only documents that contain field 'FirstName' will be returned
```csharp
// Only documents that contain field 'FirstName' will be returned

List<Employee> results = await asyncSession
.Advanced
.AsyncDocumentQuery<Employee>()
.WhereExists("FirstName")
// Or use lambda expression: .WhereExists(x => x.FirstName)
.ToListAsync();
`}
</CodeBlock>
```
</TabItem>
<TabItem value="RQL" label="RQL">
<CodeBlock language="sql">
{`// Only documents that contain field 'FirstName' will be returned
```sql
// Only documents that contain field 'FirstName' will be returned

from Employees
where exists("FirstName")
`}
</CodeBlock>
```
</TabItem>
</Tabs>

</Panel>



## Filter by field path
<Panel heading="Filter by field path">

<Tabs groupId='languageSyntax'>
<TabItem value="Sync" label="Sync">
<CodeBlock language="csharp">
{`// Only documents that contain the 'Latitude' property in the specified path will be returned
```csharp
// Only documents that contain the 'Latitude' property in the specified path will be returned

List<Employee> results = session
.Advanced
.DocumentQuery<Employee>()
.WhereExists("Address.Location.Latitude")
// Or use lambda expression: .WhereExists(x => x.Address.Location.Latitude)
.ToList();
`}
</CodeBlock>
```
</TabItem>
<TabItem value="Async" label="Async">
<CodeBlock language="csharp">
{`// Only documents that contain the 'Latitude' property in the specified path will be returned
```csharp
// Only documents that contain the 'Latitude' property in the specified path will be returned

List<Employee> results = await asyncSession
.Advanced
.AsyncDocumentQuery<Employee>()
.WhereExists("Address.Location.Latitude")
// Or use lambda expression: .WhereExists(x => x.Address.Location.Latitude)
.ToListAsync();
`}
</CodeBlock>
```
</TabItem>
<TabItem value="RQL" label="RQL">
<CodeBlock language="sql">
{`// Only documents that contain the 'Latitude' property in the specified path will be returned
```sql
// Only documents that contain the 'Latitude' property in the specified path will be returned

from Employees
where exists("Address.Location.Latitude")
`}
</CodeBlock>
```
</TabItem>
</Tabs>

</Panel>

<Panel heading="Syntax">

## Syntax

<TabItem value="whereExists_syntax" label="whereExists_syntax">
<CodeBlock language="csharp">
{`IDocumentQuery<T> WhereExists(string fieldName);

```csharp
IDocumentQuery<T> WhereExists(string fieldName);
IDocumentQuery<T> WhereExists<TValue>(Expression<Func<T, TValue>> propertySelector);
`}
</CodeBlock>
</TabItem>
```
<br/>

| Parameters | Type | Description |
| Parameter | Type | Description |
|----------------------|------------------------------|-----------------------------------------------------------------------|
| **fieldName** | `string` | The name / path of the document field to filter by |
| **propertySelector** | `Expression<Func<T,TValue>>` | Lambda expression with name / path of the document field to filter by |




</Panel>
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,86 @@ import Admonition from '@theme/Admonition';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import CodeBlock from '@theme/CodeBlock';
import Panel from "@site/src/components/Panel";
import ContentFrame from "@site/src/components/ContentFrame";

<Admonition type="note" title="">

* To filter documents by whether they contain a particular field, use the LINQ extension method `whereExists()` accessible
from the [Document Query](../../../../querying/document-query/what-is-document-query.mdx).
* Use method `whereExists()` to query for documents that contain a particular field.
A document that doesn't contain the specified field will be excluded from the query results.

* If a document doesn't contain the specified field, it is excluded from the query results.
* `whereExists()` filters documents by field presence, not by how relevant the field's value is.
When you [order results by score](../../../../querying/sorting-query-results/sort-query-results.mdx#order-by-score), `whereExists()` can contribute to that score.
For how this contribution works with Corax, see [Corax: Scoring](../../../../indexes/search-engine/corax.mdx#scoring).

* In this page:
* [Syntax](../../../../client-api/session/querying/how-to-filter-by-field.mdx#syntax)
* [Examples](../../../../client-api/session/querying/how-to-filter-by-field.mdx#examples)
* In this article:
* [Filter by field name](#filter-by-field-name)
* [Filter by field path](#filter-by-field-path)
* [Syntax](#syntax)

</Admonition>
## Syntax

<TabItem value="whereexists_1" label="whereexists_1">
<CodeBlock language="java">
{`IDocumentQuery<T> whereExists(String fieldName);
`}
</CodeBlock>
</TabItem>

| Parameters | Type | Description |
| - | - | - |
| **fieldName** | `String` | The name or path to the field you want to filter by |



## Examples

#### Filter by Field Name
<Panel heading="Filter by field name">

<Tabs groupId='languageSyntax'>
<TabItem value="Java" label="Java">
<CodeBlock language="java">
{`List<Employee> results = session
.advanced()
.documentQuery(Employee.class)
.whereExists("FirstName")
.toList();
`}
</CodeBlock>
<TabItem value="Query" label="Query">
```java
// Only documents that contain field 'FirstName' will be returned

List<Employee> results = session
.advanced()
.documentQuery(Employee.class)
.whereExists("FirstName")
.toList();
```
</TabItem>
<TabItem value="RQL" label="RQL">
<CodeBlock language="sql">
{`from Employees
```sql
// Only documents that contain field 'FirstName' will be returned

from Employees
where exists("FirstName")
`}
</CodeBlock>
```
</TabItem>
</Tabs>

</Panel>

#### Filter by the Path to a Field
<Panel heading="Filter by field path">

<Tabs groupId='languageSyntax'>
<TabItem value="Java" label="Java">
<CodeBlock language="java">
{`List<Employee> results = session
.advanced()
.documentQuery(Employee.class)
.whereExists("Address.Location.Latitude")
.toList();
`}
</CodeBlock>
<TabItem value="Query" label="Query">
```java
// Only documents that contain the 'Latitude' property in the specified path will be returned

List<Employee> results = session
.advanced()
.documentQuery(Employee.class)
.whereExists("Address.Location.Latitude")
.toList();
```
</TabItem>
<TabItem value="RQL" label="RQL">
<CodeBlock language="sql">
{`from Employees
```sql
// Only documents that contain the 'Latitude' property in the specified path will be returned

from Employees
where exists("Address.Location.Latitude")
`}
</CodeBlock>
```
</TabItem>
</Tabs>

</Panel>

<Panel heading="Syntax">

```java
IDocumentQuery<T> whereExists(String fieldName);
```
<br/>

| Parameter | Type | Description |
|---------------|----------|----------------------------------------------------|
| **fieldName** | `String` | The name / path of the document field to filter by |

</Panel>
Loading
Loading