从版本 6 升级到版本 7 后,我们在处理聚合时遇到了新的行为。现在,默认情况下,每当 Elastic 在运行 Painless 脚本时遇到字段中的空值时,它就会中断。
例如,以下简单的 if/else 语句:
if(doc['MY_FIELD'].value <= 9000)
{return 'Less than 9k' }
else if(doc['MY_FIELD'].value > 9000)
{ return ''More than 9k' }
Run Code Online (Sandbox Code Playgroud)
在版本 6 之前,我们可以毫无问题地运行此代码。然而现在,如果您尝试同样的操作,当 Elastic 处理该字段的单个空值时,它会失败。
"lang" : "painless",
"caused_by" : {
"type" : "illegal_state_exception",
"reason" : "A document doesn't have a value for a field! Use doc[<field>].size()==0 to check if a document is missing a field!"
Run Code Online (Sandbox Code Playgroud)
这使得现在必须在各处进行这种"doc[<field>].size()==0"检查。
这是关闭这个新行为并恢复前一个行为的参数吗?谢谢
似乎我遇到了某种不匹配的参考问题(对不起,我在ASP版本上非常新)。
我使用VS 2016从头开始创建一个ASP.core应用程序。我的启动课程如下:
public class Startup
{
private IHostingEnvironment _env;
private IConfigurationRoot _config;
public Startup(IHostingEnvironment env, IConfigurationRoot config)
{
_env = env;
var builder = new ConfigurationBuilder()
.SetBasePath(_env.ContentRootPath)
.AddJsonFile("config.json");
_config = builder.Build();
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(_config);
if(_env.IsEnvironment("Development"))
services.AddScoped<Services.IMailServices, Services.DebugMailService>();
services.AddMvc();
}
// This method gets called by the …Run Code Online (Sandbox Code Playgroud)