我们正在使用NEST API与使用C#的Elasticsearch一起使用。虽然我们可以插入数据,但是引用对象中特定字段的查询无法正常工作。
例如,给定以下类别:
internal class Magazine
{
public Magazine(string id, string title, string author)
{
Id = id;
Title = title;
Author = author;
}
public string Id { get; set; }
public string Title { get; set; }
public string Author { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
将创建该类的对象,并将其插入到ElasticSearch中,如下所示:
Magazine mag1= new Magazine("1", "Soccer Review", "John Smith");
Magazine mag2= new Magazine("2", "Cricket Review", "John Smith");
Uri node = new Uri("http://localhost:9200");
ConnectionSettings settings = new ConnectionSettings(node, defaultIndex: "mag-application");
ElasticClient client = new …Run Code Online (Sandbox Code Playgroud) 需要以下 JSON:
{[{"value":"1"}, {"value":"2"}, {"value":"3"}, {"value":"4"value}]}
Run Code Online (Sandbox Code Playgroud)
使用:
JsonGenerator generator = factory.createGenerator(os, JsonEncoding.UTF8);) {
generator.writeStartObject();
generator.writeFieldName("data");
generator.writeStartArray();
while (rs.next()) {
generator.writeStartObject();
generator.writeStringField("value", rs.getString("value"));
generator.writeEndObject();
}
generator.writeEndArray();
generator.writeEndObject();
generator.close();
Run Code Online (Sandbox Code Playgroud)
输出:
{"data":[{"value":"1"}, {"value":"2"}, {"value":"3"}, {"value":"4"value}]}
Run Code Online (Sandbox Code Playgroud)
我不需要数据标签,但如果
generator.writeFieldName("data");
Run Code Online (Sandbox Code Playgroud)
删除后,会抛出以下错误:
com.fasterxml.jackson.core.JsonGenerationException: Can not start an array, expecting field name (context: Object)
Run Code Online (Sandbox Code Playgroud)
这样做的正确方法是什么?
谢谢
我们有脚本通常在unix环境中执行.以下是脚本中的一行:
command => 'use/bin/tail -n 1 %{path} | grep --silent -F "%{message}" && rm -f {path}'
Run Code Online (Sandbox Code Playgroud)
在PowerShell中运行时,use/bin/tail显然无法识别路径.作为替代方案,我试过这个:
command => 'Get-Content -n 1 %{path} -Tail | grep --silent -F "%{message}" && rm -f {path}'
Run Code Online (Sandbox Code Playgroud)
但是,虽然Get-Content从PowerShell命令行本身运行时可以识别,但在脚本中运行时无法识别.这是错误消息:
"Get-Content"不被识别为内部或外部命令,可操作程序或批处理文件.
tail在PowerShell中运行脚本时,复制unix 命令的正确方法是什么?
以下存储过程用于获取参数my_seconds,创建日期变量my_date,即当前日期加上(或减去)数字my_seconds,并打印日期.
CREATE OR REPLACE PROCEDURE test (my_seconds NUMBER)
IS
my_date DATE;
BEGIN
execute immediate 'select sysdate + interval '':1'' second from dual' into my_date USING &my_seconds;
DBMS_OUTPUT.PUT_LINE('DATE:' || my_date);
END
Run Code Online (Sandbox Code Playgroud)
但是,当编译过程(使用Oracle SQL开发人员)时,它会提示输入my_seconds的值,并且无法正确创建过程.
该怎么做:
execute immediate 'select sysdate + interval '':1'' second from dual' into my_date USING &my_seconds ;
Run Code Online (Sandbox Code Playgroud)
被重写?
谢谢
我有两个案例类.主要的Request,包含两个地图.第一个映射具有键和值的字符串.第二个映射有一个字符串键,value是第二个case类的实例KVMapList.
case class Request (var parameters:MutableMap[String, String] = MutableMap[String, String](), var deps:MutableMap[String, KVMapList] = MutableMap[String, KVMapList]())
case class KVMapList(kvMap:MutableMap[String, String], list:ListBuffer[MutableMap[String, String]])
Run Code Online (Sandbox Code Playgroud)
要求是转换Request为JSON表示.以下代码尝试执行此操作:
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility
import com.fasterxml.jackson.databind.ObjectMapper
def test(req:Request):String {
val mapper = new ObjectMapper() with ScalaObjectMapper
mapper.setVisibility(PropertyAccessor.ALL, Visibility.ANY)
var jsonInString: String = null
try {
jsonInString = mapper.writeValueAsString(request)
}
catch {
=case e: IOException => {
e.printStackTrace
}
jsonString
}
Run Code Online (Sandbox Code Playgroud)
然而,这不起作用.即使Request填充了类,输出也是:
{"parameters":{"underlying":{"some-value":""},"empty":false,"traversableAgain":true},"deps":{"sizeMapDefined":false,"empty":false,"traversableAgain":true}}
Run Code Online (Sandbox Code Playgroud)
将JSON对象映射器与相应的Java类一起使用很简单,但尚未在Scala中使用它.非常感谢任何帮助.