@@ -399,6 +399,32 @@ def test_search_body(instrument, elasticapm_client, elasticsearch):
399399 assert span ["context" ]["http" ]["status_code" ] == 200
400400
401401
402+ @pytest .mark .skipif (ES_VERSION [0 ] < 7 , reason = "track_total_hits unsupported" )
403+ @pytest .mark .integrationtest
404+ def test_search_track_total_hits_false (instrument , elasticapm_client , elasticsearch ):
405+ elasticsearch .create (
406+ index = "tweets" , id = "1" , refresh = True , ** get_kwargs ({"user" : "kimchy" , "text" : "hola" , "userid" : 1 })
407+ )
408+ elasticapm_client .begin_transaction ("test" )
409+ search_query = {"query" : {"term" : {"user" : "kimchy" }}, "sort" : ["userid" ]}
410+ result = elasticsearch .search (body = search_query , track_total_hits = False )
411+ elasticapm_client .end_transaction ("test" , "OK" )
412+
413+ transaction = elasticapm_client .events [TRANSACTION ][0 ]
414+ assert result ["hits" ]["hits" ][0 ]["_source" ] == {"user" : "kimchy" , "text" : "hola" , "userid" : 1 }
415+ spans = elasticapm_client .spans_for_transaction (transaction )
416+ assert len (spans ) == 1
417+ span = spans [0 ]
418+ # Depending on ES_VERSION, could be /_all/_search or /_search, and GET or POST
419+ assert span ["name" ] in ("ES GET /_search" , "ES GET /_all/_search" , "ES POST /_search" )
420+ assert span ["type" ] == "db"
421+ assert span ["subtype" ] == "elasticsearch"
422+ assert span ["action" ] == "query"
423+ assert span ["context" ]["db" ]["type" ] == "elasticsearch"
424+ assert "rows_affected" not in span ["context" ]["db" ]
425+ assert span ["context" ]["http" ]["status_code" ] == 200
426+
427+
402428@pytest .mark .integrationtest
403429def test_search_querystring (instrument , elasticapm_client , elasticsearch ):
404430 elasticsearch .create (index = "tweets" , id = "1" , refresh = True , ** get_kwargs ({"user" : "kimchy" , "text" : "hola" }))
0 commit comments