fix #1669 logging for partial results

This commit is contained in:
Shinsuke Sugaya 2018-05-26 22:52:32 +09:00
parent bc6b1beae1
commit 15b2b82581
3 changed files with 41 additions and 0 deletions

View file

@ -61,6 +61,8 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.lastaflute.taglib.function.LaFunctions;
import org.lastaflute.web.util.LaRequestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SearchService {
@ -68,6 +70,8 @@ public class SearchService {
// Constant
//
private static final Logger logger = LoggerFactory.getLogger(SearchService.class);
// ===================================================================================
// Attribute
//
@ -117,6 +121,16 @@ public class SearchService {
.similarDocHash(params.getSimilarDocHash()).responseFields(queryHelper.getResponseFields())
.searchRequestType(params.getType()).build();
}, (searchRequestBuilder, execTime, searchResponse) -> {
searchResponse.ifPresent(r -> {
if (r.getTotalShards() != r.getSuccessfulShards() && fessConfig.isQueryTimeoutLogging()) {
// partial results
StringBuilder buf = new StringBuilder(1000);
buf.append("[SEARCH TIMEOUT] {\"exec_time\":").append(execTime)//
.append(",\"request\":").append(searchRequestBuilder.toString())//
.append(",\"response\":").append(r.toString()).append('}');
logger.warn(buf.toString());
}
});
final QueryResponseList queryResponseList = ComponentUtil.getQueryResponseList();
queryResponseList.init(searchResponse, pageStart, pageSize);
return queryResponseList;

View file

@ -564,6 +564,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. 10000 */
String QUERY_TIMEOUT = "query.timeout";
/** The key of the configuration. e.g. true */
String QUERY_TIMEOUT_LOGGING = "query.timeout.logging";
/** The key of the configuration. e.g. location */
String QUERY_GEO_FIELDS = "query.geo.fields";
@ -2994,6 +2997,20 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
Integer getQueryTimeoutAsInteger();
/**
* Get the value for the key 'query.timeout.logging'. <br>
* The value is, e.g. true <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getQueryTimeoutLogging();
/**
* Is the property for the key 'query.timeout.logging' true? <br>
* The value is, e.g. true <br>
* @return The determination, true or false. (if not found, exception but basically no way)
*/
boolean isQueryTimeoutLogging();
/**
* Get the value for the key 'query.geo.fields'. <br>
* The value is, e.g. location <br>
@ -6625,6 +6642,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return getAsInteger(FessConfig.QUERY_TIMEOUT);
}
public String getQueryTimeoutLogging() {
return get(FessConfig.QUERY_TIMEOUT_LOGGING);
}
public boolean isQueryTimeoutLogging() {
return is(FessConfig.QUERY_TIMEOUT_LOGGING);
}
public String getQueryGeoFields() {
return get(FessConfig.QUERY_GEO_FIELDS);
}
@ -8282,6 +8307,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
defaultMap.put(FessConfig.INDEX_INDICES_TIMEOUT, "1m");
defaultMap.put(FessConfig.QUERY_MAX_LENGTH, "1000");
defaultMap.put(FessConfig.QUERY_TIMEOUT, "10000");
defaultMap.put(FessConfig.QUERY_TIMEOUT_LOGGING, "true");
defaultMap.put(FessConfig.QUERY_GEO_FIELDS, "location");
defaultMap.put(FessConfig.QUERY_BROWSER_LANG_PARAMETER_NAME, "browser_lang");
defaultMap.put(FessConfig.QUERY_REPLACE_TERM_WITH_PREFIX_QUERY, "true");

View file

@ -287,6 +287,7 @@ index.indices.timeout=1m
# query
query.max.length=1000
query.timeout=10000
query.timeout.logging=true
query.geo.fields=location
query.browser.lang.parameter.name=browser_lang
query.replace.term.with.prefix.query=true