0

我正在尝试创建一个如前所示的索引,但我总是收到此错误: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 应用程序(主要)上尝试了这段代码,它可以工作。有什么理由呢?

4

2 回答 2

2

由于上面的代码不是我想这是您发送的读取或 JSON 的问题 - 请提供有关您期望的模型的更多详细信息,以及读取

于 2015-01-20T15:20:38.173 回答
1

可能是您的示例不完整,但是从上面的代码中,您有两个打开的花括号和一个闭合的花括号。

于 2015-01-20T15:59:44.957 回答