Hello,
I am trying to perform some unit testing in grails and doing a simple test I
appear to be able to index but a following search will find nothing. Here is
an example:
// Setup the test node and client @Before
public void init() {
assertNotNull dataSource
GNodeBuilder nodeBuilder = nodeBuilder()
nodeBuilder.settings {
node {
local = true
}
cluster {
name = "Integration Test"
}
}
testNode = nodeBuilder.node()
testClient = testNode.client
assertNotNull testNode
assertNotNull testClient
}
// Perform a simple index followed by a simple search @Test
void simpleTest() {
def indexF = testClient.index {
index "inventory"
type "aType"
id "1"
source {
code = "somecode"
}
}
println "Indexed id ${indexF.response.id}"
def searchF = testClient.search {
indices "inventory"
types "aType"
source {
query {
term(code: "somecode")
}
}
}
// This should get a hit but I receive nothing.
println "Search Result"
searchF.response.hits.each {SearchHit hit ->
println "Got hit $hit.id from ${hit.index}/${hit.type}"
}
Hello,
I am trying to perform some unit testing in grails and doing a simple test
I appear to be able to index but a following search will find nothing. Here
is an example:
// Setup the test node and client @Before
public void init() {
assertNotNull dataSource
GNodeBuilder nodeBuilder = nodeBuilder()
nodeBuilder.settings {
node {
local = true
}
cluster {
name = "Integration Test"
}
}
testNode = nodeBuilder.node()
testClient = testNode.client
assertNotNull testNode
assertNotNull testClient
}
// Perform a simple index followed by a simple search @Test
void simpleTest() {
def indexF = testClient.index {
index "inventory"
type "aType"
id "1"
source {
code = "somecode"
}
}
println "Indexed id ${indexF.response.id}"
def searchF = testClient.search {
indices "inventory"
types "aType"
source {
query {
term(code: "somecode")
}
}
}
// This should get a hit but I receive nothing.
println "Search Result"
searchF.response.hits.each {SearchHit hit ->
println "Got hit $hit.id from ${hit.index}/${hit.type}"
}
Not sure exactly what the deal is but when I switched to the Java API I was
able to get it to work.
Perhaps it was something I missed with the Groovy API that resulted in an
error or exception that didn't get raised, I'll revisit later.
Hello,
I am trying to perform some unit testing in grails and doing a simple test
I appear to be able to index but a following search will find nothing. Here
is an example:
// Setup the test node and client @Before
public void init() {
assertNotNull dataSource
GNodeBuilder nodeBuilder = nodeBuilder()
nodeBuilder.settings {
node {
local = true
}
cluster {
name = "Integration Test"
}
}
testNode = nodeBuilder.node()
testClient = testNode.client
assertNotNull testNode
assertNotNull testClient
}
// Perform a simple index followed by a simple search @Test
void simpleTest() {
def indexF = testClient.index {
index "inventory"
type "aType"
id "1"
source {
code = "somecode"
}
}
println "Indexed id ${indexF.response.id}"
def searchF = testClient.search {
indices "inventory"
types "aType"
source {
query {
term(code: "somecode")
}
}
}
// This should get a hit but I receive nothing.
println "Search Result"
searchF.response.hits.each {SearchHit hit ->
println "Got hit $hit.id from ${hit.index}/${hit.type}"
}
The previous answer is the correct one, and has nothing to do with Java API
or Groovy API, you need to call refresh right after the index operation to
see it, otherwise, it will be refreshed in the background periodically. It
might be that the Java test you wrote got into the timing window where it
refreshed after the index operation.
Not sure exactly what the deal is but when I switched to the Java API I was
able to get it to work.
Perhaps it was something I missed with the Groovy API that resulted in an
error or exception that didn't get raised, I'll revisit later.
Hello,
I am trying to perform some unit testing in grails and doing a simple
test I appear to be able to index but a following search will find nothing.
Here is an example:
// Setup the test node and client @Before
public void init() {
assertNotNull dataSource
GNodeBuilder nodeBuilder = nodeBuilder()
nodeBuilder.settings {
node {
local = true
}
cluster {
name = "Integration Test"
}
}
testNode = nodeBuilder.node()
testClient = testNode.client
assertNotNull testNode
assertNotNull testClient
}
// Perform a simple index followed by a simple search @Test
void simpleTest() {
def indexF = testClient.index {
index "inventory"
type "aType"
id "1"
source {
code = "somecode"
}
}
println "Indexed id ${indexF.response.id}"
def searchF = testClient.search {
indices "inventory"
types "aType"
source {
query {
term(code: "somecode")
}
}
}
// This should get a hit but I receive nothing.
println "Search Result"
searchF.response.hits.each {SearchHit hit ->
println "Got hit $hit.id from ${hit.index}/${hit.type}"
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.