Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Time difference between Elasticsearch "took" and that calculated manually

I can't figure out why is there such a difference between ES time and the query time.

var url = "192.168.100.11:9200";
var elasticsearch = require('elasticsearch');

var client = new elasticsearch.Client({
    host: url
});
var accounts = [];   
var startTime = new Date();
client.search({"index":"test", "type":"testdata1", searchType:"count"}).then(
    function (searchData) {
        var endDate = new Date();
        console.log(" total time : [" + (endDate - startTime) + "]")
        console.log(" ES   >>>>> :" + JSON.stringify(searchData.took));
    }).catch(function (err) {
        console.log(" errr  >>>> :" + err);
    });

Output:

total time : [37]

ES >>>>> :2

As you can see, es result took shows query was executed in 2 ms, but if I calculate total time taken to run in code , it took 37ms. What took 35ms ?

like image 557
ashu.v Avatar asked Feb 12 '15 11:02

ashu.v


People also ask

What is Took in Elasticsearch response?

“Took” parameter of Elasticsearch response is the correct indicator of the total time taken by a query (including time spent on sending requests to all relevant shards and gathering and combining the results from all shards).

How do I get more than 10000 records in Elasticsearch Python?

You can use scroll API to retrieve more than 10000 records in elastic search as by default, 10000 is the upper cap for the number of documents returned.

What are hits in Elasticsearch?

A search consists of one or more queries that are combined and sent to Elasticsearch. Documents that match a search's queries are returned in the hits, or search results, of the response. A search may also contain additional information used to better process its queries.

What is term query in Elasticsearch?

Term queryedit. Returns documents that contain an exact term in a provided field. You can use the term query to find documents based on a precise value such as a price, a product ID, or a username.


1 Answers

According to this thread, the 'took' value measures wall time of query execution in Elasticsearch, which includes queue waiting time but excludes

  • serializing the request into JSON on the client
  • sending the request over the network
  • deserializing the request from JSON on the server
  • serializing the response into JSON on the server
  • sending the response over the network
  • deserializing the response from JSON on the client
like image 79
user161107 Avatar answered Oct 28 '22 23:10

user161107