Search code examples
c#asp.net-corenestdsl

How to obtain data count from NEST that is not exact What data count does the DSL query return?


My Old DSL query from which i am getting 2237 records from same index and link

../design/_count?pretty=true
{
    "query": {
        "bool": {
            "must": {
                "match_all": {}
            },
            "filter": {
                "geo_distance": {
                    "distance": "872.70344mi",
                    "location": {
                        "lat": 47.52,
                        "lon": -121.87
                    }
                }
            }
        }
    }
}

My NEST query by which I am getting 11093 records, total nine thousand records differance.

public async Task<long> GetEsDataCountByGeoDistanceAsync<T>(string indexName) where T : class
        {
            var searchResponse = await _elasticClient.CountAsync<T>(s => s
                                 .Index(indexName)
                                 .Query(q => q
                                   .Bool(b => b
                                    .Must(m => m
                                      .MatchAll())
                                    .Filter(f => f
                                      .GeoDistance(go => go
                                        .Distance("872.70344mi")
                                        .Location(47.52, -121.87))
                                      )))
                                 ).ConfigureAwait(false);

            return searchResponse.Count;
        }

so where I am missing some by which i am getting miss match data?


Solution

  • Thanks @Rob, I was tried with that syntax so I can saw actual DSL query behind above NEST query and solved by below query, actually was need to send field name for get geo distance..but dnt know why this is different with above DSL query..

    public async Task<long> GetEsDataCountByGeoDistanceAsync<T>(string indexName,string fieldName, double latitude, double longtitude, string distance) where T : class
            {
                var searchResponse = await _elasticClient.CountAsync<T>(s => s
                                     .Index(indexName)
                                     .Query(q => q
                                       .Bool(b => b
                                        .Must(m => m
                                          .MatchAll())
                                        .Filter(f => f
                                          .GeoDistance(go => go
                                            .Field(fieldName)
                                            .Distance(distance)
                                            .Location(latitude, longtitude))
                                          )))
                                     ).ConfigureAwait(false);
                return searchResponse.Count;
            }