我将 MongoDB 与 Elastic Search 集成
我已经使用以下命令从终端索引了数据库“testmongo”中的集合“person”:
curl -XPUT 'http://localhost:9200/_river/mongodb/_meta' -d '{
"type": "mongodb",
"mongodb": {
"db": "testmongo",
"collection": "person"
},
"index": {
"name": "mongoindex",
"type": "person"
}
}'
并通过 mongo 终端向 mongodb 添加一些数据:
use testmongo
var p = {firstName: "John", lastName: "Doe"}
db.person.save(p)
使用此命令搜索数据:
curl -XGET 'http://localhost:9200/mongoindex/_search?q=firstName:John'
直到这里一切正常
我的问题是这样的:
如何,我必须创建客户端节点来查询我有以下代码不起作用:
package code
package snippet
import net.liftweb._
import http._
import common._
import util.Helpers._
import scala.xml._
import org.elasticsearch.node.NodeBuilder._
import org.elasticsearch.index.query.QueryBuilders._
import collection.JavaConversions._
class SearchTerms extends StatefulSnippet with Loggable{
private var term = ""
def dispatch = {
case "render" => render _
}
def render( xhtml: NodeSeq ): NodeSeq = {
def doSearchTerm {
val node = nodeBuilder().client(true).node()
val client = node.client()
val query = queryString( term )
val response = client
.prepareSearch("A")
.setTypes("B")
.setQuery(query)
.execute()
.actionGet()
val hits = response.getHits
logger.info( "Found %d hits for query '%s'".format( hits.getTotalHits, term ) )
hits.getHits.foreach(hit =>
logger.info("* %s".format(hit.sourceAsMap()("text")))
)
client.close()
node.close()
}
我必须在 A 和 B 中使用哪些值才能使用 scala lift 中的搜索功能
有人可以帮帮我吗
非常感谢您的关注