Time Difference with "took" and python timer

Hello everyone, I am very new in Elasticsearch and also in forum. I have created an index, then I have created some queries. When I checked the "took" time from kibana for my queries, it is between 7 and 10ms. However, when I check it with :

start_time = time.time()
response = requests.post(url=search_url, headers=headers, data=payload, auth=HTTPBasicAuth(ElasticConfig.ELASTIC_USERNAME, ElasticConfig.ELASTIC_PASSWORD))
Logger.info(f"Taken time by elasticsearch is {time.time()-start_time}")

It shows nearly 50 ms. I know that serialization and deserializations are not involved in "took". I use "JSON" for serialization and deserialization. Actually, I don't know what should I do next to speed up my queries . Thank you for your comments.

Version is Elasticsearch 7.9.1

Welcome to our community! :smiley:

Is 50ms too slow?

Hi @warkolm , actually we are planning to use it for production; therefore, 20-25 ms would be perfect.

Ok, well what's the query you are running?


  "size": 100,
  "from": 0,
  "min_score": 0,
  "query": {
    "bool": {
      "filter": [
        {
          "match": {
            "country_code": country.upper()
          }
        }
      ],
      "must": [
        {
          "multi_match": {
            "query": keyword,
            "fuzziness": 1,
            "prefix_length": 1,
            "fields": [
              "product_name_en.productName^1",
              "product_name_en.productName_wo_autocomplete^2",
              "product_name_en.productName_multiple^0.4",
              "subcategory_name_en^1",
              "category_name_en^0.4",
              "total_name_adj_en^1",
              "product_name_tr.productName^0.2",
              "product_name_tr.productName_wo_autocomplete^0.4",
              "product_name_tr.productName_multiple^0.1",
              "subcategory_name_tr^0.2",
              "category_name_tr^0.1",
              "total_name_adj_tr^0.2",
              "product_name_fr.productName^0.2",
              "product_name_fr.productName_wo_autocomplete^0.4",
              "product_name_fr.productName_multiple^0.1",
              "subcategory_name_fr^0.2",
              "category_name_fr^0.1",
              "total_name_adj_fr^0.2",
              "product_name_nl.productName^0.2",
              "product_name_nl.productName_wo_autocomplete^0.4",
              "product_name_nl.productName_multiple^0.1",
              "subcategory_name_nl^0.2",
              "category_name_nl^0.1",
              "total_name_adj_nl^0.2",
              "product_name_de.productName^0.2",
              "product_name_de.productName_wo_autocomplete^0.4",
              "product_name_de.productName_multiple^0.1",
              "subcategory_name_de^0.2",
              "category_name_de^0.1",
              "total_name_adj_de^0.2",
              "product_name_es.productName^0.2",
              "product_name_es.productName_wo_autocomplete^0.4",
              "product_name_es.productName_multiple^0.1",
              "subcategory_name_es^0.2",
              "category_name_es^0.1",
              "total_name_adj_es^0.2",
              "product_name_it.productName^0.2",
              "product_name_it.productName_wo_autocomplete^0.4",
              "product_name_it.productName_multiple^0.1",
              "subcategory_name_it^0.2",
              "category_name_it^0.1",
              "total_name_adj_it^0.2",
              "product_name_pt.productName^0.2",
              "product_name_pt.productName_wo_autocomplete^0.4",
              "product_name_pt.productName_multiple^0.1",
              "subcategory_name_pt^0.2",
              "category_name_pt^0.1",
              "total_name_adj_pt^0.2"
            ]
          }
        }
      ]
    }
  }

Also, the first queries are slower, when they are compared to following queries.

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