-
Notifications
You must be signed in to change notification settings - Fork 51
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
Integration of ElasticSearch v1.0 (GROUND - 6) #68
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bunch of comments inline. Tests are also failing on the CI build.
pom.xml
Outdated
<dependency> | ||
<groupId>org.elasticsearch</groupId> | ||
<artifactId>elasticsearch</artifactId> | ||
<version>1.5.1</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version should be a variable in the properties field of the POM.
import edu.berkeley.ground.dao.models.NodeVersionFactory; | ||
import edu.berkeley.ground.dao.models.StructureFactory; | ||
import edu.berkeley.ground.dao.models.StructureVersionFactory; | ||
import edu.berkeley.ground.dao.models.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using the Google Java style guide which specifies no *
imports.
@@ -28,4 +28,5 @@ | |||
public abstract List<Long> getVersionIdsByTag(String tag) throws GroundException; | |||
|
|||
public abstract List<Long> getItemIdsByTag(String tag) throws GroundException; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove unnecessary whitespace.
public List<Long> getVersionIdsByTag(String tag) throws GroundException { | ||
return this.getIdsByTag(tag, "rich_version"); | ||
return ElasticSearch.getSearchResponse("rich_version", tag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably have a configuration option that allows people to turn on / off ElasticSearch use. Let's add a field to the config and pass it through to the TagFactory
. If it's turned off, we can go to the regular database (current impl.), and if it's turned on, we can use the ElasticSearch API.
LOGGER.info("Retrieving all item ids with tag: " + tag + "."); | ||
return this.tagFactory.getItemIdsByTag(tag); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace.
String json = mapper.writeValueAsString(tag); | ||
IndexResponse response = client.prepareIndex(clusterName, table, Long.toString(tag.getId())) | ||
.setSource(json).get(); | ||
client.admin().indices().prepareRefresh().execute().actionGet(); // need to refresh index with new inserted item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly does refreshing an index do? Do we need to do it on every insert?
return response.isCreated(); | ||
|
||
} catch (JsonProcessingException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Printing the stack trace isn't the right thing to do. We should pass the error information through with the exception that we throw.
|
||
public static List<Long> getSearchResponse(String type, String searchQuery) throws GroundException { | ||
SearchResponse response = client.prepareSearch().setTypes(type).setQuery(QueryBuilders.matchQuery("key", searchQuery)).get(); | ||
SearchHit[] hits = response.getHits().getHits(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is .getHits().getHits()
an ES API idiosyncrasy?
import edu.berkeley.ground.dao.models.NodeVersionFactory; | ||
import edu.berkeley.ground.dao.models.StructureFactory; | ||
import edu.berkeley.ground.dao.models.StructureVersionFactory; | ||
import edu.berkeley.ground.dao.models.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No *
imports.
@@ -52,7 +54,7 @@ | |||
protected static CassandraTagFactory tagFactory; | |||
|
|||
@BeforeClass | |||
public static void setup() throws GroundDbException { | |||
public static void setup() throws GroundDbException, GroundException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't throw both. GroundDbException
is a subclass of GroundException
.
Please also put the name of the JIRA issue (GROUND-6) in square brackets at the beginning of the PR for consistency. :-) |
@nipunramk: Looks like the build is still failing. |
Added ability to insert into ElasticSearch and get search responses by key values in tags and also by ids. Added a ElasticSearch.java util file in the utils folder with all relevant helper methods. Getting list of ids through a tag key now goes through ElasticSearch. Also set up a TagResources endpoint.