Search code examples
c#elasticsearchnest

Elasticsearch Nest : Fetching random documents


I am trying to get random records using Elastic Search NEST client. Is there any way to do this?


Solution

  • To compliment @pickypg's answer, here's an example of how to compose a function_score query with a random_score function in NEST:

    client.Search<MyType>(s => s
        .Query(q => q
            .FunctionScore(fs => fs
                .Query(fq => fq.MatchAll())
                .RandomScore()
            )
        )
    );