简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM