FilterContainer in Elasticsearch NEST 5.0


(iluvcode) #1

I am working on Elasticsearch migration from 1.7.1 to 5.0.
I fixed most of the issues in the code after upgrading to 5.0 but I couldn't figure out how to change FilterContainer to work in new version.

Below is my code

 public static List<**FilterContainer**> GetPriceRangeFilters(SearchListCriteria criteria, out List<**FilterContainer**> additionalpricefilters)
        {
            var pricefilters = new List<**FilterContainer**>();
            additionalpricefilters = new List<**FilterContainer**>();
            if (criteria.SearchGlobalSettings.MinimumPriceRange != null && criteria.SearchGlobalSettings.MinimumPriceRange.Length > 0)
            {
                const string fieldName = "itemPrices.webPrice";
                pricefilters.Add((new **FilterDescriptor**<ItemSearchEntry>()).Query(a => a.Range(n => n.OnField(fieldName).GreaterOrEquals(criteria.SearchGlobalSettings.MinimumPriceRange[0].ToString()).
                    LowerOrEquals(criteria.SearchGlobalSettings.MaximumPriceRange[0].ToString()))));
                for (var i = 1; i < criteria.SearchGlobalSettings.MinimumPriceRange.Length; i++)
                {
                    additionalpricefilters.Add((new **FilterDescriptor**<ItemSearchEntry>()).Query(a => a.Range(n => n.OnField(fieldName).
                        GreaterOrEquals(criteria.SearchGlobalSettings.MinimumPriceRange[i].ToString()).LowerOrEquals(criteria.SearchGlobalSettings.MaximumPriceRange[i].ToString()))));
                }
            }
            return pricefilters;
        }

(Russ Cam) #2

FilterContainer no longer exists in NEST 2.0 onwards, because filters and queries merged in Elasticsearch into queries, with a query or filter context.

Where you would have used FilterContainer, use QueryContainer and then when adding to the search, pass the collection of FilterContainer into a bool query filter clause.


(iluvcode) #3

I was able to convert filter containers to Query containers. Still working on indexing issues. Thanks for your help.


(system) #4

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