#304 - ElasticSearch integration part 1 / doc store integration

This commit is contained in:
Robin Bygrave
2016-03-01 15:36:44 +13:00
parent cb1fe297d6
commit 8d3b4a0407
209 changed files with 6736 additions and 573 deletions
@@ -6,9 +6,12 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import com.avaje.ebeaninternal.server.el.ElPropertyDeploy;
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
import com.avaje.ebeaninternal.server.expression.ElasticExpressionContext;
import com.avaje.ebeaninternal.server.query.SplitName;
import com.fasterxml.jackson.core.JsonGenerator;
import javax.persistence.PersistenceException;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
@@ -498,4 +501,67 @@ public class OrmQueryDetail implements Serializable {
public Set<String> getFetchPaths() {
return fetchPaths.keySet();
}
/**
* Write the Elastic search source include and fields if necessary.
* <p>
* Fetch all property is put into includes.
* Fetch on 'many' path is put into includes.
* Fetch on 'one' paths and root path are put into fields.
* </p>
*/
public void writeElastic(ElasticExpressionContext context) throws IOException {
Set<String> includes = new LinkedHashSet<String>();
Set<String> fields = new LinkedHashSet<String>();
for (Map.Entry<String, OrmQueryProperties> entry : fetchPaths.entrySet()) {
String path = entry.getKey();
OrmQueryProperties value = entry.getValue();
if (value.allProperties()) {
includes.add(path + ".*");
} else if (context.containsMany(path)) {
for (String propName : value.getIncluded()) {
includes.add(path + "." + propName);
}
} else {
for (String propName : value.getIncluded()) {
fields.add(path + "." + propName);
}
}
}
if (hasSelectClause()) {
Set<String> included = baseProps.getIncluded();
if (included != null) {
for (String propName : included) {
fields.add(propName);
}
}
}
if (!includes.isEmpty()) {
JsonGenerator json = context.json();
json.writeFieldName("_source");
json.writeStartObject();
json.writeFieldName("include");
json.writeStartArray();
for (String propName : includes) {
json.writeString(propName);
}
json.writeEndArray();
json.writeEndObject();
}
if (!fields.isEmpty()) {
JsonGenerator json = context.json();
json.writeFieldName("fields");
json.writeStartArray();
for (String propName : fields) {
json.writeString(propName);
}
json.writeEndArray();
}
}
}