我正在尝试通过postman发送elasticserach多搜索请求,如下所示:
POST - http://localhost:9200/_msearch
content-type : x-www-form-urlencoded
body:
{"index":"accounts"}
{"query":{"bool":{"should":[{"match":{"owner.first_name":"Creeple"}}]}}}
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
{
"error": {
"root_cause": [
{
"type": "parse_exception",
"reason": "Failed to derive xcontent"
}
],
"type": "parse_exception",
"reason": "Failed to derive xcontent"
},
"status": 400
}
Run Code Online (Sandbox Code Playgroud)
请注意,如果我通过播放代码执行相同的请求,则会成功获取结果.
WS.url("localhost:9200/_msearch").withHeaders("Content-type" -> "application/x-www-form-urlencoded").post(query)
Run Code Online (Sandbox Code Playgroud) 有Either在阶其允许变量具有2种值.
val x: Either[String, Int] = Left("apple")
Run Code Online (Sandbox Code Playgroud)
但是,我希望变量x有两种以上的类型,例如{String, Int, Double, List[String] }.
e.g. val x:[type can be either String, Int, Double or List[String]]
//So that I can store either String, Int, Double, List[String] value in x.
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?
我正在尝试使用以下方式在 MongoDB 中插入日期:
collection.insert(Json.obj("user"->"abc", "joined_date" -> DateTime.now))
Run Code Online (Sandbox Code Playgroud)
在数据库中:
{
"_id" : ObjectId("5865d99718969bca6a09450f"),
"user" : "abc",
"joined_date" : NumberLong("1483069847066")
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是日期以长毫秒格式存储在数据库中,但我想要的是它以 ISO 日期格式存储。
我在 MongoShell 中尝试保存相同的数据db.example.insert({user:"abc", joined_date:new Date()}),结果如下:
{
"_id" : ObjectId("5865d838a4f98c5bb83b1eb8"),
"user" : "abc",
"joined_date" : ISODate("2016-12-30T03:44:56.824Z")
}
Run Code Online (Sandbox Code Playgroud)
那么,如何使用 ReactiveMongo 在数据库中以 ISODate 格式存储日期?
scala mongodb playframework reactivemongo play-reactivemongo
目前,我正在学习Scala并阅读本书" Scala编程",其中写道:"与数组或列表不同,元组可以容纳不同类型的对象." 例如,以下元组包含Int,String和Float.
val tup = (1, "hello", 4.4)
Run Code Online (Sandbox Code Playgroud)
同样,该书说,"如果你想在列表/数组中有任何类型的元素,那么你可以使用任何数据类型."
val list = List[Any](1, "hello", 4.4)
Run Code Online (Sandbox Code Playgroud)
那么,这两种方法之间的区别是什么?一个人比另一个人有什么好处?
目前,我正在学习 Scala,现在,我对比较对象的有序特征有些困惑。
考虑下面的例子,这是我目前对比较的理解,
Case I,
class Example(var n: Int) extends Ordered[Example] {
// ...
def compare(that: Example) =
(this.n) - (that.n)
}
var obj1 = new Example(12)
var obj2 = new Example(12)
obj1 compare obj2 //return 0 i.e. obj1 and obj2 are equal.
Case II,
class Example(var m: Int, var n: Int) extends Ordered[Example] {
// ...
def compare(that: Example) =
(this.m * this.n) - (that.m * that.n)
}
var obj1 = new Example(1, 2)
var obj2 = new Example(1, …Run Code Online (Sandbox Code Playgroud) 我嵌套了如下地图:
val x: Map[String, Any] =
Map("a" -> "apple", "b" -> "ball", "c" -> Map("x" -> "cat", "y" -> 12))
Run Code Online (Sandbox Code Playgroud)
我想把它转换成:
Map("a" -> "apple", "b" -> "ball", "x" -> "cat", "y" -> 12)
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试将 flatten 调用到 x ,则会出现异常。
x.flatten
Error:(40, 14) No implicit view available from (String, Any) => scala.collection.GenTraversableOnce[B].
println(mx.flatten)
Error:(40, 14) not enough arguments for method flatten: (implicit asTraversable: ((String, Any)) => scala.collection.GenTraversableOnce[B])scala.collection.immutable.Iterable[B].
Unspecified value parameter asTraversable.
println(x.flatten)
Run Code Online (Sandbox Code Playgroud)
那么,如何提供隐式视图以展平上述地图?