Elasticsearch.net How to write a query in c#

Hello everyone!

How convert write a below query into another working query using c# elsaticsearch.net

Currently I'm using this C# query:

Queries.Add(Query<IndexModel>.Bool(b => b.Should(filter => filter
                                    .GeoDistance(geo => geo
                                            .Field(f => f.Location) //<- this 
                                            .Distance(searchModel.Location.Position.Range.Value, Nest.DistanceUnit.Miles)
                                            .Location(searchModel.Location.Position.Latitude.Value, searchModel.Location.Position.Longitude.Value)
                                    ))));

Queries.Add(Query<IndexModel>.Bool(b => b.Should(filter => filter
                                    .GeoDistance(geo => geo
                                            .Field(f => f.MasterLocations) //<- this 
                                            .Distance(searchModel.Location.Position.Range.Value, Nest.DistanceUnit.Miles)
                                            .Location(searchModel.Location.Position.Latitude.Value, searchModel.Location.Position.Longitude.Value)
                                    ))));

Existing query;

  "track_total_hits": true,
  "from": 0,
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "geo_distance": {
                  "distance": "10mi",
                  "location": {
                    "lat": 33.393915,
                    "lon": -112.134149
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "geo_distance": {
                  "distance": "10mi",
                  "masterLocations": {
                    "lat": 33.393915,
                    "lon": -112.134149
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "size": 200,
  "sort": [
    {
      "nVCNumber": {
        "missing": "_last",
        "order": "asc"
      }
    }
  ]
}

I need the below format query:

{
  "track_total_hits": true,
  "from": 0,
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "geo_distance": {
                  "distance": "10mi",
                  "location": {
                    "lat": 33.393915,
                    "lon": -112.134149
                  }
                }
              },
              {
                "geo_distance": {
                  "distance": "10mi",
                  "masterLocations": {
                    "lat": 33.393915,
                    "lon": -112.134149
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "size": 200
}

Thanks in Advance!

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