Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch 2.1 - Deprecated search types

According to this link, both scan and count are deprecated.

I am trying to change my queries to reflect this. So the count change is easy, just removing the search type and adding size=0 to the request, however, I am not 100% on the scan change.

Currently I have this query:

var result = ElasticClient.Search<Product>(s => s
    .From(0)
    .Size(10)
    .SearchType(SearchType.Scan)
    .Scroll("4s")
    .Query
        (qu =>
            qu.Filtered
                (fil =>
                    fil.Filter
                        (f =>
                            f.Bool(b => b.Must(m => m.Term("filedName", "abc")))))));

Am I correct in my understanding that all I need to change is remove the searchtype and add a sort? I.e:

var result = ElasticClient.Search<Product>(s => s
    .From(0)
    .Size(10)
    .Scroll("4s")
    .Sort(x => x.OnField("_doc"))
    .Query
        (qu =>
            qu.Filtered
                (fil =>
                    fil.Filter
                        (f => f.Bool(b => b.Must(m => m.Term("filedName", "abc")))))));

I have seen a enum SortSpecialField here, but I am not sure how to actually use this in the sort parameter.

like image 784
Robin Rieger Avatar asked Jan 12 '16 21:01

Robin Rieger


1 Answers

You're correct in your understanding that the change (as you document in your question) to sort by _doc will replace the deprecated Scan searchtype. The SortSpecialField enum is just syntax sugar for sorting by _doc. If you prefer to use it, in NEST 2.0 [only], you can do this:

ElasticClient.Search<Product>(s => s
.From(0)
.Size(10)
.Scroll("4s")
.Sort(x => x.Ascending(SortSpecialField.DocumentIndexOrder))
    ...
like image 57
Dusty Avatar answered Nov 15 '22 07:11

Dusty