我正在尝试创建一个如前所示的索引,但我总是收到此错误:Bad request For request 'POST /initIndex' [Invalid Json]
我正在使用带有 play Framework 2.3.x 和 scala 2.11 的 elastic4s。
import com.sksamuel.elastic4s.{ElasticClient, ElasticsearchClientUri, FrenchLanguageAnalyzer}
import com.sksamuel.elastic4s.ElasticDsl._
import com.sksamuel.elastic4s.mappings.FieldType._
import models.tools.Tool
import org.elasticsearch.action.get.GetResponse
import org.elasticsearch.action.search.SearchResponse
import scala.concurrent.Future
object ToolsDaoImpl {
private val uri: ElasticsearchClientUri = ElasticsearchClientUri("elasticsearch://localhost:9200")
private val client = ElasticClient.remote(uri)
def createIndex {
client execute {
create index name mappings (
"tool" as (
"id" typed IntegerType,
"title" typed StringType analyzer FrenchLanguageAnalyzer,
"description" typed StringType analyzer FrenchLanguageAnalyzer
)
)
}
}
def findById(toolId: Long): Future[GetResponse] = client.execute {
get id toolId from "tools/tool"
}
def findByName(name: String): Future[SearchResponse] = client.execute {
search in "tools/tool" query name
}
def initIndex {
client.execute {
index into "tools/tool" doc Tool(id = 1L, title = "Marteau", description = "Peut être utilisé pour differents travaux")
index into "tools/tool" doc Tool(id = 1L, title = "Perceuse", description = "Placoplatre et béton")
}
}
}
case class Tool(id: Long, title: String, city: String, description: String) extends DocumentMap {
override def map: Map[String, Any] = Map("id" -> id, "title" -> title, "description" -> description)
}
它直接从控制器调用。没有其他的
任何想法 ?
提前致谢。
编辑:我在一个简单的 scala 应用程序(主要)上尝试了这段代码,它可以工作。有什么理由呢?