默认情况下,NEST会在将对象发送到Elasticsearch进行索引时使用驼峰大小写对象和属性名称.如何在NEST中为Elasticsearch文档禁用骆驼套管字段名称?我做了大量的研究,并且有关于这个主题的邮件列表主题,但它似乎已经过时,因为一些方法已被重命名或不再存在.
IConnectionPool connectionPool = new SniffingConnectionPool(m_ElasticsearchNodeUris);
ConnectionSettings settings = new ConnectionSettings(connectionPool);
settings.SetDefaultTypeNameInferrer(p => p.Name); //This disables camel casing for object type names
ElasticClient client = new ElasticClient(settings);
Run Code Online (Sandbox Code Playgroud)
邮件列表中的信息表明应添加此代码以处理字段名称,但客户端方法似乎不存在:
client.ModifyJsonSerializationSettings(s => s.ContractResolver = new Nest.Resolvers.ElasticResolver(settings);
Run Code Online (Sandbox Code Playgroud)
有没有人有任何更新的语法来处理这个?谢谢.
我正在构建一个API应用程序,它基本上允许用户构建一个文档,该文档可以根据需要进行结构化,并存储在Elasticsearch中.从本质上讲,我为用户提供了一个简单的界面来访问我们的Elasticsearch实例.我正在努力使实现尽可能简单.这是我到目前为止所处理的问题.
预期身体的对象:
public class DocumentModel
{
public string Index { get; set; }
public string Type { get; set; }
public string Id { get; set; }
[ElasticProperty(Type = FieldType.Nested)]
public dynamic Document { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
简单实施:
[HttpPost]
[Route("")]
public IHttpActionResult Post(DocumentModel document)
{
Uri nodeLocation = new Uri("http://localhost:9200");
IConnectionPool connectionPool = new SniffingConnectionPool(new List<Uri> { nodeLocation });
ConnectionSettings settings = new ConnectionSettings(connectionPool);
ElasticClient esClient = new ElasticClient(settings);
IIndexResponse result = esClient.Index(document, i => i
.Index(document.Index)
.Type(document.Type)
.Id(document.Id)); …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用其OAuth
身份验证工作流程来获取针对Salesforce在.NET中验证MVC应用程序的实例.我一直在参考这个非常简单的演练.这与让Google身份验证工作非常相似.它归结为使用个人帐户身份验证模板设置.NET MVC项目,并在Salesforce中启动新的连接应用程序.然后,添加Owin.Security.Providers
库的Salesforce,调整Startup.Auth.cs了一下,包括ClientId
和ClientSecret
从Salesforce的应用程序,授权和令牌端点.它建议的回调网址是http:// localhost:[port]/signin-salesforce,这与用于Google身份验证的回调网址非常相似.
当我被重定向到Salesforce并且可以登录时,将我返回到我的MVC应用程序的握手似乎遇到了一个我无法确定的问题.我被重定向回登录页面,.NET似乎并不知道我的登录信息,虽然我肯定有一个与Salesforce的活动会话(Salesforce仪表板将自动登录我).在代码中,事情开始在这里横行:
// GET: /Account/ExternalLoginCallback
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
//more code we never reach
}
Run Code Online (Sandbox Code Playgroud)
loginInfo
永远是空的.因此,为了弄清楚将什么类型的请求发送到.NET,我转向Fiddler并遇到一个请求反对localhost:[port]/signin-salesforce
一堆参数得到一个奇怪的响应:
找到HTTP/1.1 302
位置:/ Account/ExternalLoginCallback?error = access_denied
服务器:Microsoft-IIS/10.0
Set-Cookie:.AspNet.Correlation.Salesforce =; 路径= /; expires =周四,01-Jan-1970 00:00:00 GMT
X-SourceFiles:????= UTF-8乙YzpcdXNlcnNcc3RldmUuY2FtaXJlXGRvY3VtZW50c1x2aXN1YWwgc3R1ZGlvIDIwMTVcUHJvamVjdHNcU2FsZXNGb3JjZUludGVncmF0aW9uXFNhbGVzRm9yY2VJbnRlZ3JhdGlvblxzaWduaW4tc2FsZXNmb3JjZQ == =
X-Powered-By:ASP.NET
日期:2016年5月20日星期五21:46:09 GMT
内容长度:0
请注意Location标头,它告诉.NET重定向到/Account/ExternalLoginCallback
错误参数"access_denied".启用一些跟踪Owin …
我有一个物联网主题从设备接收数据。每个 IoT 负载都包含一些属性和对象数组,如下所示。
{
"batchId": "someBatchId",
"prop1": "someProp1",
"objArray": [
{
"arrString1": "someArrString1",
"arrString2": "someArrString2",
"arrNum1": 1,
"arrNum2": 2,
"arrString3": "someArrString3"
},
{
"arrString1": "someArrString4",
"arrString2": "someArrString5",
"arrNum1": 3,
"arrNum2": 4,
"arrString3": "someArrString6"
}
]
}
Run Code Online (Sandbox Code Playgroud)
该数组中可以包含数百个对象。我们希望使用一个Map
步骤来展平这些数据,并将顶级属性与数组中的每个元素相关联,并将该元素插入到 DynamoDB 中。我们的桌子设置和物联网主题运行得很好。
我们遇到的问题是 DynamoDB 在插入数字时需要字符串。但是,由于我们从 IoT 以 JSON 对象的形式接收这些数据,并且数字位于对象数组内部,因此我们很难将数字转换为字符串。因此,我们希望 Step Function 以某种方式将数字转换为字符串,但我不知道该怎么做。这里的目标是构建一个简单的管道,用于将 IoT 数据存储到 DynamoDB 中。
我们也不能完全控制可以发送的所有属性,因此我们还在 S3 中存储 IoT 有效负载的副本(它已经与 IoT 规则引擎连接并且工作得很好),但这更多的是备份和包罗万象。我们最感兴趣的是进入 DynamoDB 的数据,以便我们可以实际查询它。我们如何说服 Step Function 将 JSON 有效负载中的数字插入 DynamoDB 中?
我怀疑我有一个死锁问题,但这是一个奇怪的问题,我无法合理化.我有一个API需要验证一些事情来处理呼叫.作为业务逻辑的一部分,我可能还需要进行更多相同的调用.在这种情况下,如果未找到与实体关联的特定数据,我们将尝试使用备份(如果已配置),这需要检查其他实体.最终,代码将挂起.
让我们深入研究代码(评论突出显示有问题的电话).
API控制器:
public async Task<HttpResponseMessage> Get(int entityID, string content, bool? useBackUp = true)
{
//Some look-ups here, no issues at all
//This works, but it's this method that has an issue later in the process.
SystemEntity entityObj =
await BusinessLayer.GetSystemEntityAsync(SystemEntityID);
if (entityObj == null)
{
return new HttpResponseMessage
{
StatusCode = System.Net.HttpStatusCode.BadRequest,
Content = new StringContent("Entity is unavailable.")
};
}
string text = BusinessLayer.GetContentTextAsync(entityID
new List<string> {contentName}, useBackUp).Result.FirstOrDefault().Value;
if (text == null)
{
return new HttpResponseMessage {StatusCode = System.Net.HttpStatusCode.NoContent}; …
Run Code Online (Sandbox Code Playgroud)