0

ELK noob here. I have an index with 10000 documents and I define a filter for date range and it gives me 500 documents. I want to get 50 random documents.

I am trying to do this using python.

It would really help if someone can direct me towards an example.

This is my code block

search_body = {
  "query": {
    "bool": {
      "must": [
        {"match": {
          "customer_gender": "MALE"
        }}
      ],
      "filter": [
        {"range": {
          "order_date": {
            "gte": "2022-03-27"
          }
        }}
      ]
    }
  }
}

results = scan(client, index="sample_data", query=search_body)
for hit in results:
   print(hit)

I want to add the randomness to it. I suppose function_score may be the I need to look at, but a working example can really help.

jnan
  • 35
  • 3
  • Does this answer your question? [ElasticSearch random score combined with boost?](https://stackoverflow.com/questions/45164568/elasticsearch-random-score-combined-with-boost) – Sagar Patel Mar 24 '22 at 05:36
  • That did help. instead of using helpers.scan, I used client.search with size. That seems like giving the right result. – jnan Apr 05 '22 at 15:19

0 Answers0