Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public class QueryParserSettings {
float tieBreaker = 0.0f;
boolean useDisMax = true;

public boolean isCacheable() {
// a hack for now :) to determine if a query string is cacheable
return !queryString.contains("now");
}

public String queryString() {
return queryString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,20 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

builder.startObject(Fields.SEGMENTS);
for (Segment segment : shardSegments) {
builder.startObject(segment.name());
builder.field(Fields.GENERATION, segment.generation());
builder.field(Fields.NUM_DOCS, segment.numDocs());
builder.field(Fields.DELETED_DOCS, segment.deletedDocs());
builder.field(Fields.SIZE, segment.size().toString());
builder.field(Fields.SIZE_IN_BYTES, segment.sizeInBytes());
builder.field(Fields.COMMITTED, segment.committed());
builder.field(Fields.SEARCH, segment.search());
builder.startObject(segment.getName());
builder.field(Fields.GENERATION, segment.getGeneration());
builder.field(Fields.NUM_DOCS, segment.getNumDocs());
builder.field(Fields.DELETED_DOCS, segment.getDeletedDocs());
builder.field(Fields.SIZE, segment.getSize().toString());
builder.field(Fields.SIZE_IN_BYTES, segment.getSizeInBytes());
builder.field(Fields.COMMITTED, segment.isCommitted());
builder.field(Fields.SEARCH, segment.isSearch());
if (segment.getVersion() != null) {
builder.field(Fields.VERSION, segment.getVersion());
}
if (segment.isCompound() != null) {
builder.field(Fields.COMPOUND, segment.isCompound());
}
builder.endObject();
}
builder.endObject();
Expand Down Expand Up @@ -166,5 +172,7 @@ static final class Fields {
static final XContentBuilderString SIZE_IN_BYTES = new XContentBuilderString("size_in_bytes");
static final XContentBuilderString COMMITTED = new XContentBuilderString("committed");
static final XContentBuilderString SEARCH = new XContentBuilderString("search");
static final XContentBuilderString VERSION = new XContentBuilderString("version");
static final XContentBuilderString COMPOUND = new XContentBuilderString("compound");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public List<Segment> getSegments() {
public int getNumberOfCommitted() {
int count = 0;
for (Segment segment : segments) {
if (segment.committed()) {
if (segment.isCommitted()) {
count++;
}
}
Expand All @@ -74,7 +74,7 @@ public int getNumberOfCommitted() {
public int getNumberOfSearch() {
int count = 0;
for (Segment segment : segments) {
if (segment.search()) {
if (segment.isSearch()) {
count++;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ public final boolean readBoolean() throws IOException {
return readByte() != 0;
}

@Nullable
public final Boolean readOptionalBoolean() throws IOException {
byte val = readByte();
if (val == 2) {
return null;
}
if (val == 1) {
return true;
}
return false;
}

/**
* Resets the stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public void writeDouble(double v) throws IOException {

private static byte ZERO = 0;
private static byte ONE = 1;
private static byte TWO = 2;

/**
* Writes a boolean.
Expand All @@ -244,6 +245,14 @@ public void writeBoolean(boolean b) throws IOException {
writeByte(b ? ONE : ZERO);
}

public void writeOptionalBoolean(@Nullable Boolean b) throws IOException {
if (b == null) {
writeByte(TWO);
} else {
writeByte(b ? ONE : ZERO);
}
}

/**
* Forces any buffered output to be written.
*/
Expand Down
39 changes: 38 additions & 1 deletion src/main/java/org/elasticsearch/http/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.env.Environment;
import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.PluginsService;
import org.elasticsearch.rest.*;
import org.elasticsearch.rest.action.support.RestXContentBuilder;

import java.io.File;
import java.io.IOException;
Expand All @@ -49,19 +53,22 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {

private final NodeService nodeService;

private final PluginsService pluginsService;

private final boolean disableSites;

private final PluginSiteFilter pluginSiteFilter = new PluginSiteFilter();

@Inject
public HttpServer(Settings settings, Environment environment, HttpServerTransport transport,
RestController restController,
NodeService nodeService) {
NodeService nodeService, PluginsService pluginsService) {
super(settings);
this.environment = environment;
this.transport = transport;
this.restController = restController;
this.nodeService = nodeService;
this.pluginsService = pluginsService;
nodeService.setHttpServer(this);

this.disableSites = componentSettings.getAsBoolean("disable_sites", false);
Expand Down Expand Up @@ -150,6 +157,13 @@ void handlePluginSite(HttpRequest request, HttpChannel channel) {
int i1 = path.indexOf('/');
String pluginName;
String sitePath;


if (path.length() == 0) {
handlePluginList(request, channel);
return;
}

if (i1 == -1) {
pluginName = path;
sitePath = null;
Expand Down Expand Up @@ -191,6 +205,29 @@ void handlePluginSite(HttpRequest request, HttpChannel channel) {
}
}

private void handlePluginList(HttpRequest request, HttpChannel channel) {
ImmutableMap<String, Plugin> plugins = pluginsService.plugins();
try {

XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
if (request.paramAsBoolean("pretty", false))
builder.prettyPrint();

builder.startObject();
builder.startArray("plugins");

for (String pluginName : plugins.keySet()) {
builder.value(pluginName);
}
builder.endArray();
builder.endObject();

channel.sendResponse(new XContentRestResponse(request, OK, builder));
} catch (IOException e) {
channel.sendResponse(new StringRestResponse(INTERNAL_SERVER_ERROR));
}
}


// TODO: Don't respond with a mime type that violates the request's Accept header
private String guessMimeType(String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import org.elasticsearch.index.IndexComponent;

/**
*
* The main benefit of the query parser cache is to not parse the same query string on different shards.
* Less about long running query strings.
*/
public interface QueryParserCache extends IndexComponent, CloseableComponent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import org.apache.lucene.queryparser.classic.QueryParserSettings;
import org.apache.lucene.search.Query;
import org.elasticsearch.ElasticSearchException;
Expand Down Expand Up @@ -50,8 +49,8 @@ public class ResidentQueryParserCache extends AbstractIndexComponent implements
public ResidentQueryParserCache(Index index, @IndexSettings Settings indexSettings) {
super(index, indexSettings);

this.maxSize = indexSettings.getAsInt("index.cache.field.max_size", componentSettings.getAsInt("max_size", 100));
this.expire = indexSettings.getAsTime("index.cache.field.expire", componentSettings.getAsTime("expire", null));
this.maxSize = componentSettings.getAsInt("max_size", 100);
this.expire = componentSettings.getAsTime("expire", null);
logger.debug("using [resident] query cache with max_size [{}], expire [{}]", maxSize, expire);

CacheBuilder cacheBuilder = CacheBuilder.newBuilder().maximumSize(maxSize);
Expand All @@ -69,7 +68,9 @@ public Query get(QueryParserSettings queryString) {

@Override
public void put(QueryParserSettings queryString, Query query) {
cache.put(queryString, query);
if (queryString.isCacheable()) {
cache.put(queryString, query);
}
}

@Override
Expand Down

This file was deleted.

Loading