---
# System prepended metadata

title: Elastic raw querying

---

# Elastic raw querying

When using the Elastic search provider, Ucommerce supports raw queries to the provider in two forms: raw JSON and NEST queries.

This is for special requirements, when you need functionality not covered by the Ucommerce search APIs.

## Examples

### Raw JSON string

You can pass a JSON string to the `FindRaw()` method. This query is then forwarded to the provider followed by the default skip, take and sort parameters.

```csharp
 var query = @"{
     ""term"" : { 
         ""Sku"" : {""value"":""shirt""} 
        }  
     }";
     
var products = Index.FindRaw(query).ToList();
```

For further information on what is supported by the provider, please visit the [Elastic documentation.](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/raw-query-usage.html)

### Nest query

If you are looking to use DSL to query instead, you can do this by passing a `Nest.SearchDescriptor<T>` instance to the `FindRaw()` method.

```csharp
var query =
        new SearchDescriptor<TestProduct>()
            .Query(q => 
                q.Match(m => 
                    m.Field(f => f.Sku)
                        .Query("shirt")
                )
            );

var products = Index.FindRaw(query).ToList();
```

For further information on querying using DLS, please visit the [Elastic documentation.](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/query-dsl.html)

### Custom model queries

When retrieving data from a raw query, it is possible to specify a custom model by providing it as a type argument to the `FindRaw<T>()` method. This is useful when, for example, you want a subset of the fields returned only from the index for a particular query.

This works with both syntaxes mentioned above.


```csharp
    public class CustomProduct: Model
    {
        public string Name { get; set; }
        public int Id { get; set; }
    }
```
```csharp
    var query =
            new SearchDescriptor<CustomProduct>()
                .Query(q => 
                    q.Match(m => 
                        m.Field(f => f.Id)
                            .Query("23")
                    )
                );

    var products = Index.FindRaw<CustomProduct>(query).ToList();
```