loki
loki

Reputation: 2966

How can i write a query by using Nest Elasticsearch by C# ?

My question is simple. I can write a very awesome queries in postman ;

POST : localhost:9200/logstash-2017.08.28/_search?pretty=true

{
	"query":{
		"match":{
			
			"level":"Error"
		}
	}
	
}

But I have to this thing inside of C# code by using nest framework.But i can not do that can you help me?

   var response = EsClient().Search<DocumentAttributes>(s => s
                .Index("logstash-2017.09.18")
                .Type("json")
                .Query(q => q
                .Term(p => p.level, "Error")));

             //.Query(q => q.Raw(@"level:Error")));
             //      .Type("type").Query(q => q.Raw(@"{""match_all"":{}}")));

How can i write down by writing query or by using fields?

Upvotes: 0

Views: 261

Answers (1)

Ruben Vardanyan
Ruben Vardanyan

Reputation: 1308

Your queries are not the same. For json query you specified the following path localhost:9200/logstash-2017.08.28/_search?pretty=true, which means you are going to search for all documents in index logstash-2017.08.28.

Lets see what you have in query written using NEST.

  1. Index method means that you are going to search for all documents in the given index
  2. Type method means that you are going to query all documents in given index which has the given type. In your case type is json. So Type method is for defining on which type of documents are you going to search.

So, the difference between your queries is that in first case you are querying all the documents in the index, but in second case you are querying all the documents in the index with type json.

Upvotes: 2

Related Questions