Commit fb7a5e35 authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add some logging to es requests

parent 40aed859
Pipeline #20533 passed with stages
in 5 minutes and 15 seconds
......@@ -19,22 +19,15 @@ package org.memobase.helpers
import com.beust.klaxon.Klaxon
import com.beust.klaxon.KlaxonException
import java.net.ConnectException
import java.net.SocketTimeoutException
import java.util.Properties
import kotlin.system.exitProcess
import org.apache.http.HttpHost
import org.apache.logging.log4j.LogManager
import org.elasticsearch.ElasticsearchException
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest
import org.elasticsearch.action.search.ClearScrollRequest
import org.elasticsearch.action.search.SearchRequest
import org.elasticsearch.action.search.SearchScrollRequest
import org.elasticsearch.client.RequestOptions
import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestHighLevelClient
import org.elasticsearch.client.core.CountRequest
import org.elasticsearch.client.indices.GetIndexRequest
import org.elasticsearch.common.unit.TimeValue
import org.elasticsearch.index.query.QueryBuilders.termQuery
import org.elasticsearch.search.Scroll
......@@ -66,6 +59,7 @@ class ElasticSearchWrapper(
* @return Number of Documents
*/
fun countNumberOfDocuments(recordSetIdentifier: String): Int {
log.info("Counting documents for record set $recordSetIdentifier.")
val request = CountRequest(documentsIndex)
request.query(
termQuery(
......@@ -76,7 +70,9 @@ class ElasticSearchWrapper(
val response = client.count(
request, RequestOptions.DEFAULT
)
response.count.toInt()
val count = response.count.toInt()
log.info("Found $count documents for record set $recordSetIdentifier.")
count
} catch (ex: ElasticsearchException) {
log.error(ex.detailedMessage)
0
......@@ -93,6 +89,7 @@ class ElasticSearchWrapper(
*/
fun getDocumentTypesFromRecords(recordSetIdentifier: String, queryField: String): List<FacetContainer> {
return try {
log.info("Attempting to load document type for $recordSetIdentifier in field $queryField.")
val resultFacets = mutableListOf<FacetContainer>()
val typeSet = mutableSetOf<String>()
val scroll = Scroll(TimeValue.timeValueMinutes(1L))
......@@ -111,7 +108,6 @@ class ElasticSearchWrapper(
)
)
searchRequest.source(searchSourceBuilder)
var searchResponse = client.search(searchRequest, RequestOptions.DEFAULT)
var scrollId = searchResponse.scrollId
var searchHits = searchResponse.hits.hits
......@@ -140,6 +136,7 @@ class ElasticSearchWrapper(
val clearScrollRequest = ClearScrollRequest()
clearScrollRequest.addScrollId(scrollId)
client.clearScroll(clearScrollRequest, RequestOptions.DEFAULT)
log.info("Found the following types $typeSet for record set $recordSetIdentifier.")
resultFacets
} catch (ex: ElasticsearchException) {
log.error(ex.detailedMessage)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment