Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now view plugin is compatible with 0.90.11 version of elasticsearch. #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.tlrx</groupId>
<groupId>com.github.luizgpsantos</groupId>
<artifactId>elasticsearch-view-plugin</artifactId>
<version>0.0.3-SNAPSHOT</version>
<version>0.0.5-SNAPSHOT</version>
<packaging>jar</packaging>

<name>elasticsearch-view-plugin</name>
Expand All @@ -17,7 +17,7 @@
</parent>

<properties>
<elasticsearch.version>0.20.5</elasticsearch.version>
<elasticsearch.version>0.90.11</elasticsearch.version>
<mvel2.version>2.1.3.Final</mvel2.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down Expand Up @@ -72,14 +72,14 @@
</dependencies>

<scm>
<url>git:[email protected]:tlrx/elasticsearch-view-plugin.git</url>
<connection>scm:git:git@github.com:tlrx/elasticsearch-view-plugin.git</connection>
<developerConnection>scm:git:[email protected]:tlrx/elasticsearch-view-plugin.git</developerConnection>
<url>git:[email protected]:luizgpsantos/elasticsearch-view-plugin.git</url>
<connection>scm:[email protected]:luizgpsantos/elasticsearch-view-plugin.git</connection>
<developerConnection>scm:git:[email protected]:luizgpsantos/elasticsearch-view-plugin.git</developerConnection>
</scm>

<issueManagement>
<system>GitHub</system>
<url>https://github.com/tlrx/elasticsearch-view-plugin/issues/</url>
<url>https://github.com/luizgpsantos/elasticsearch-view-plugin/issues/</url>
</issueManagement>

<build>
Expand Down Expand Up @@ -144,7 +144,6 @@
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
package org.elasticsearch.action.view;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.ElasticSearchIllegalArgumentException;
import org.elasticsearch.ElasticSearchParseException;
Expand All @@ -31,7 +36,6 @@
import org.elasticsearch.cluster.block.ClusterBlockLevel;
import org.elasticsearch.cluster.metadata.MappingMetaData;
import org.elasticsearch.cluster.routing.ShardIterator;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -43,15 +47,10 @@
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.view.exception.ElasticSearchViewNotFoundException;
import org.elasticsearch.view.ViewContext;
import org.elasticsearch.view.ViewResult;
import org.elasticsearch.view.ViewService;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.elasticsearch.view.exception.ElasticSearchViewNotFoundException;


public class TransportViewAction extends TransportShardSingleOperationAction<ViewRequest, ViewResponse> {
Expand Down Expand Up @@ -117,7 +116,7 @@ protected ViewResponse shardOperation(ViewRequest request, int shardId) throws E
IndexShard indexShard = indexService.shardSafe(shardId);
GetResult getResult = indexShard.getService().get(request.type(), request.id(), null, false);

if (!getResult.exists()) {
if (!getResult.isExists()) {
throw new ElasticSearchIllegalArgumentException("Document not found, cannot render view");
}

Expand All @@ -142,10 +141,10 @@ protected ViewResponse shardOperation(ViewRequest request, int shardId) throws E
}

// Set some org.elasticsearch.test.integration.views.mappings.data required for view rendering
viewContext.index(getResult.index())
.type(getResult.type())
.id(getResult.id())
.version(getResult.version())
viewContext.index(getResult.getIndex())
.type(getResult.getType())
.id(getResult.getId())
.version(getResult.getVersion())
.source(getResult.sourceAsMap());

// Ok, let's render it with a ViewEngineService
Expand Down Expand Up @@ -283,7 +282,7 @@ private ViewContext extract(Map<String, Object> sourceAsMap, String format) {
}

SearchResponse searchResponse = searchAction.execute(searchRequest).get();
viewContext.queriesAndHits(queryName, searchResponse.hits());
viewContext.queriesAndHits(queryName, searchResponse.getHits());

} catch (Exception e) {
viewContext.queriesAndHits(queryName, null);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/elasticsearch/action/view/ViewRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.elasticsearch.action.support.single.shard.SingleShardOperationRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Required;

public class ViewRequest extends SingleShardOperationRequest<ViewRequest> {

Expand Down Expand Up @@ -59,7 +58,6 @@ public ViewRequest type(@Nullable String type) {
/**
* Sets the id of the document to fetch.
*/
@Required
public ViewRequest id(String id) {
this.id = id;
return this;
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/elasticsearch/view/ViewContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
*/
package org.elasticsearch.view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.index.get.GetField;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.SearchHits;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ViewContext {

private String lang;
Expand All @@ -40,7 +39,6 @@ public class ViewContext {
private String id;
private Long version;
private Map<String, Object> source;
private Map<String, Object> fields;
private Map<String, SearchHits> queries;

public ViewContext(String lang, String view, String contentType) {
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/org/elasticsearch/view/ViewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,27 @@
*/
package org.elasticsearch.view;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Set;

import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.collect.ImmutableSet;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.env.Environment;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.view.binary.BinaryViewEngineService;
import org.elasticsearch.view.mvel.MvelViewEngineService;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;

public class ViewService extends AbstractComponent {

private final String defaultViewLang;

private final ImmutableMap<String, ViewEngineService> viewEngines;

private final ConcurrentMap<String, CompiledScript> staticCache = ConcurrentCollections.newConcurrentMap();

public ViewService(Settings settings) {
this(settings, new Environment(), ImmutableSet.<ViewEngineService>builder()
.add(new MvelViewEngineService(settings))
Expand Down