Skip to content
Browse files

Add a test for ES filter queries

  • Loading branch information...
1 parent d6589ed commit a16604bbf77db9991b581c3cfa4eb8b64771820b @holdenk holdenk committed May 31, 2012
View
35 src/test/scala/com/foursquare/slashem/ElasticQueryTest.scala
@@ -365,7 +365,7 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
def testObjectIdListFieldEmptyNin {
val response1 = ESimplePanda where (_.favvenueids nin List()) fetch()
Assert.assertEquals(response1.response.results.length, 8)
- }
+ }
@Test
def testListFieldNin {
@@ -404,13 +404,39 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
Assert.assertEquals(res1.response.results.length, 1)
}
+ @Test
+ def testFilters {
+ // grab 2 results, filter to 1
+ val res1 = ESimplePanda where (_.hugenums contains 1L) filter(_.nicknamesString in List("jerry")) fetch()
+ Assert.assertEquals(res1.response.results.length, 1)
+ }
+
+
@Before
def hoboPrepIndex() {
ESimplePanda.meta.node = ElasticNode.node
ESimpleGeoPanda.meta.node = ElasticNode.node
+ //Setup the mapping for the regular index
val client = ESimplePanda.meta.client
-
-
+ try {
+ val indexReq = Requests.createIndexRequest(ESimplePanda.meta.indexName)
+ client.admin.indices().create(indexReq).actionGet()
+ client.admin().indices().prepareRefresh().execute().actionGet()
+ val indexName = ESimplePanda.meta.indexName
+ val mapping = """
+ { "slashemdoc" :{
+ "properties" : {
+ "nicknamesString" : { type: "string", store: "no", analyzer:"whitespace"}
+ }
+ }}"""
+ val mappingReq = Requests.putMappingRequest(ESimplePanda.meta.indexName).source(mapping).`type`("slashemdoc")
+ val mappingResponse = client.admin().indices().putMapping(mappingReq).actionGet()
+ } catch {
+ case e => {
+ e.printStackTrace();
+ println("Error creating the regular index, may allready exist ("+e+")")
+ }
+ }
//Set up the geo panda index
val geoClient = ESimpleGeoPanda.meta.client
try {
@@ -466,6 +492,7 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
.field("id","4c809f4251ada1cdc3790b10")
.field("favnums", favnums1)
.field("nicknames", nicknames1)
+ .field("nicknamesString", nicknames1.asScala.mkString(" "))
.field("hugenums", hugenums1)
.field("termsfield", terms1)
.field("favvenueids", venueids1)
@@ -481,6 +508,7 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
.field("foreign","pants")
.field("favnums", favnums2)
.field("nicknames", nicknames2)
+ .field("nicknamesString", nicknames2.asScala.mkString(" "))
.field("hugenums", hugenums2)
.endObject()
).execute()
@@ -495,6 +523,7 @@ class ElasticQueryTest extends SpecsMatchers with ScalaCheckMatchers {
.field("foreign","pants")
.field("favnums", favnums3)
.field("nicknames", nicknames3)
+ .field("nicknamesString", nicknames3.asScala.mkString(" "))
.field("hugenums", hugenums3)
.endObject()
).execute()
View
2 src/test/scala/com/foursquare/slashem/ElasticTest.scala
@@ -4,6 +4,7 @@ object ESimplePanda extends ESimplePanda with ElasticMeta[ESimplePanda] {
//Force local for testing
override val useTransport = false
override val clusterName = "simpletest" //Override me knthx
+ override val indexName = "esimplepanda"
}
class ESimplePanda extends ElasticSchema[ESimplePanda] {
def meta = ESimplePanda
@@ -17,6 +18,7 @@ class ESimplePanda extends ElasticSchema[ESimplePanda] {
object foreign extends SlashemStringField(this)
object favnums extends SlashemIntListField(this)
object nicknames extends SlashemStringListField(this)
+ object nicknamesString extends SlashemStringField(this)
object hugenums extends SlashemLongListField(this)
object termsfield extends SlashemUnanalyzedStringField(this)
object favvenueids extends SlashemObjectIdListField(this)

0 comments on commit a16604b

Please sign in to comment.
Something went wrong with that request. Please try again.