Issue in POST request to Elastic Search using Nest in .NET

In Get Request i get Data when i try using POSTMAN Client.

image

In same way if try the post request then i wont get data as response

Valid NEST response built from a successful low level call on POST: /bankpayoutsummary/data/_search?typed_keys=true
# Audit trail of this API call:
 - [1] PingSuccess: Node: http://localhost:9200/ Took: 00:00:00.0419916
 - [2] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.2869426
# Request:
{"query":{"term":{"taluka":{"value":"Pauni"}}}}
# Response:
{"took":1,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

POST Data using Nest it show zero document count.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Nest;
using WebElastic.ConnectionSetter;
using WebElastic.Models;

namespace WebElastic.Controllers
{
    public class Default1Controller : Controller
    {
        private ConnectionToEs ConnectionToEs;
        public Default1Controller()
        {
            ConnectionToEs = new ConnectionToEs();
        }
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Search(string q)
        {
            var response = ConnectionToEs.EsClient().Search<Bankpayoutsummary>(s => s
                .Index("bankpayoutsummary")
                .Type("data")
                .Query(m => m.Term(t => t.Field("taluka").Value("Pauni")))); //Search based in _id          

            var result = response.Documents;

            return View("Search", result);
        }
    }
}

POST Data Response.

Screenshot_4
what is wrong in POST request.

What version of NEST are you using, and what version of Elasticsearch are you targeting?

@forloop Its 6.0.0

And version of Elasticsearch?

1 Like

Version 6.0.0

Screenshot_5

What's the version of Elasticsearch that you are running queries against?

Version 6.0.0

Your search query in Postman is not the same as your search query in NEST.

In Postman

GET http://localhost:9200/bankpayoutsummary/data/_search?q=taluka=Pauni

is a query_string query, equivalent to

client.Search<Bankpayoutsummary>(s => s
	.Index("bankpayoutsummary")
	.Type("data")
	.Query(q => q
		.QueryString(qs => qs
			.Query("taluka=Pauni")
		)
	)
);

with NEST. This would generate the following query

POST http://localhost:9200/bankpayoutsummary/data/_search
{
  "query": {
    "query_string": {
      "query": "taluka=Pauni"
    }
  }
}

I also think you might want taluka:Pauni for your query, with the supported syntax

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.