Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ElasticSearch NEST Query

I'm trying to mimic a query that I wrote in Sense (chrome plugin) using NEST in C#. I can't figure out what the difference between the two queries is. The Sense query returns records while the nest query does not. The queries are as follows:

var searchResults = client.Search<File>(s => s.Query(q => q.Term(p => p.fileContents, "int")));

and

{
"query": {
    "term": {
       "fileContents": {
          "value": "int"
       }
    }
}

What is the difference between these two queries? Why would one return records and the other not?

like image 786
Nived Avatar asked Mar 31 '15 19:03

Nived


People also ask

What is Elasticsearch nest?

"Elasticsearch is a distributed, open source search and analytics engine for all types of data, including textual, numerical, geospatial, structured, and unstructured. Elasticsearch is built on Apache Lucene and was first released in 2010 by Elasticsearch N.V. (now known as Elastic).

What is nested type in Elasticsearch?

The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way that they can be queried independently of each other.

What nested fields?

When a packed class contains an instance field that is a packed type, the data for that field is packed directly into the containing class. The field is known as a nested field .


1 Answers

You can find out what query NEST uses with the following code:

var json = System.Text.Encoding.UTF8.GetString(searchResults.RequestInformation.Request);

Then you can compare the output.

like image 194
Matthew Jones Avatar answered Sep 30 '22 04:09

Matthew Jones