带对象的ElasticSearch null_value? [英] ElasticSearch null_value with an object?

查看:96
本文介绍了带对象的ElasticSearch null_value?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在ElasticSearch中将对象用于 null_value 映射?

Is it possible to use an object for the null_value mapping in ElasticSearch?

{
   "properties-v3": {
      "mappings": {
         "property": {
            "properties": {
               // ... omitting lots of properties for brevity
               "stats": { // <-- Need to populate this if null
                  "properties": {
                     "bookings": {
                        "type": "long",
                        "null_value": 0
                     },
                     "enquiries": {
                        "type": "long",
                        "null_value": 0
                     },
                     "favorites": {
                        "type": "long",
                        "null_value": 0
                     },
                     "pageViews": {
                        "type": "long",
                        "null_value": 0
                     }
                  }
               },
               // ... more properties here
            }
         }
      }
   }
}

如果统计信息属性为null,我想创建一个对象,并根据其null_value映射填充属性。在基础属性上指定null_value似乎不起作用。

If the stats property in the mapping above is null, I'd like to create an object with the properties populated as per their null_value mappings. Specifying null_value on the underlying properties does not seem to work.

ElasticSearch是否允许对象进行null值映射?

Will ElasticSearch allow for null_value mapping for objects?

推荐答案

首先,让我们看看null_value的作用。对于字段name,如果将null_value设置为某个值,则不会将此信息添加到_source,但是该值将转到反向索引。这意味着您可以基于null_value搜索,但是不会在_source中显示。

First , lets see what null_value does. For a field , name , if there is null_value is set to some value , it wont add this information to _source , but rather this value will go to the reverse index. This means that you can search based on the null_value , but it wont be shown in _source.

要举一个例子,可以说我正在索引以下文档-

To spot an example , lets say i am indexing the following document -

{
  "class" : "10m
  "address" : "abcs"
}

在此,对于字段名称,我们将null_value启用为 John
如果我执行以下查询-

Here , lets say , for the field name we have enabled null_value as "John" Now if i execute the following query -

{
   "query" : {
             "match" : {
                   "name" : "john"
              }
   }
}

即使没有字段值john也会匹配上一个文档,但是返回的文档中不会显示该值,这意味着_source不会改变,只是改变整个上下文的搜索能力行为。

It will match the previous document even if it don't have a field name with value john. But then in the document returned this value wont be shown. This means that _source is not changed in anyway , just that we are changing the search-ability behavior of the entire context.

现在回到您的问题-如果您想将null_value放在对象中,例如
的字段名称,将以下对象作为空值

Now coming back to your question - if you want to put null_value to a object say , for the field name , put the following object as null_value

{
   "first_name" : "john",
   "last_name" : "dep"
}

然后,可能的是分配将name.first_name和name.last_name两个字段的null_value分别设置为john和dep。

Then , what is possible would be to assign null_value to both fields name.first_name and name.last_name as john and dep respectively.

这篇关于带对象的ElasticSearch null_value?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆