精华内容
下载资源
问答
  • nested fragments

    2018-06-01 16:14:35
    nested fragments nested fragments nested fragments nested fragments
  • 干货 | Elasticsearch Nested类型深入详解

    万次阅读 多人点赞 2018-10-06 13:08:20
    0、概要 在Elasticsearch实战场景中,我们或多或少会遇到嵌套文档的组合形式,反映在ES中称为父子文档。 父子文档的实现,至少包含以下两种方式: ...2)Nested嵌套类型 本文通过一个例...

    Elasticsearch 最少必要知识实战教程直播回放

    0、概要

    在Elasticsearch实战场景中,我们或多或少会遇到嵌套文档的组合形式,反映在ES中称为父子文档。
    父子文档的实现,至少包含以下两种方式:
    1)父子文档
    父子文档在5.X版本中通过parent-child父子type实现,即:1个索引对应多个type;
    6.X+版本已经不再支持一个索引多个type,6.X+的父子索引的实现改成Join。
    2)Nested嵌套类型

    本文通过一个例子将Nested类型适合解决的问题、应用场景、使用方法串起来,
    文中所有的DSL都在Elasticsearch6.X+验证通过。

    1、Elasticsearch 数据类型全景概览

    在这里插入图片描述

    2、从一个例子说起吧

    在这里插入图片描述

    2.1 问题背景

    在elasticsearch中,我们可以将密切相关的实体存储在单个文档中。 例如,我们可以通过传递一系列评论来存储博客文章及其所有评论。
    举例:

    {
      "title": "Invest Money",
      "body": "Please start investing money as soon...",
      "tags": ["money", "invest"],
      "published_on": "18 Oct 2017",
      "comments": [
        {
          "name": "William",
          "age": 34,
          "rating": 8,
          "comment": "Nice article..",
          "commented_on": "30 Nov 2017"
        },
        {
          "name": "John",
          "age": 38,
          "rating": 9,
          "comment": "I started investing after reading this.",
          "commented_on": "25 Nov 2017"
        },
        {
          "name": "Smith",
          "age": 33,
          "rating": 7,
          "comment": "Very good post",
          "commented_on": "20 Nov 2017"
        }
      ]
    }
    

    如上所示,所以我们有一个文档描述了一个帖子和一个包含帖子上所有评论的内部对象评论。
    但是Elasticsearch搜索中的内部对象并不像我们期望的那样工作。

    2.2 问题出现

    现在假设我们想查找用户{name:john,age:34}评论过的所有博客帖子。 让我们再看一下上面的示例文档,找到评论过的用户。

    name age
    William 34
    John 38
    Smith 33

    从列表中我们可以清楚地看到,没有34岁的用户John。
    为简单起见,我们在elasticsearch索引中只有1个文档。
    让我们通过查询索引来验证它:

    GET /blog/_search?pretty
    {
      "query": {
        "bool": {
          "must": [
            {
              "match": {
                "comments.name": "John"
              }
            },
            {
              "match": {
                "comments.age": 34
              }
            }
          ]
        }
      }
    }
    

    我们的示例文档作为回复返回。 很惊讶,这是为什么呢?

    2.3 原因分析

    这就是为什么我说:
    elasticsearch中的内部对象无法按预期工作
    这里的问题是elasticsearch(lucene)使用的库没有内部对象的概念,因此内部对象被扁平化为一个简单的字段名称和值列表。
    我们的文档内部存储为:

    {
      "title":                    [ invest, money ],
      "body":                     [ as, investing, money, please, soon, start ],
      "tags":                     [ invest, money ],
      "published_on":             [ 18 Oct 2017 ]
      "comments.name":            [ smith, john, william ],
      "comments.comment":         [ after, article, good, i, investing, nice, post, reading, started, this, very ],
      "comments.age":             [ 33, 34, 38 ],
      "comments.rating":          [ 7, 8, 9 ],
      "comments.commented_on":    [ 20 Nov 2017, 25 Nov 2017, 30 Nov 2017 ]
    }
    

    如上,您可以清楚地看到,comments.name和comments.age之间的关系已丢失。
    这就是为什么我们的文档匹配john和34的查询。

    2.4 如何解决呢?

    要解决这个问题,我们只需要对elasticsearch的映射进行一些小改动。
    如果您查看索引的映射,您会发现comments字段的类型是object。
    我们需要更新它的类型为nested。
    我们可以通过运行以下查询来简单地更新索引的映射:

    PUT /blog_new
    {
      "mappings": {
        "blog": {
          "properties": {
            "title": {
              "type": "text"
            },
            "body": {
              "type": "text"
            },
            "tags": {
              "type": "keyword"
            },
            "published_on": {
              "type": "keyword"
            },
            "comments": {
              "type": "nested",
              "properties": {
                "name": {
                  "type": "text"
                },
                "comment": {
                  "type": "text"
                },
                "age": {
                  "type": "short"
                },
                "rating": {
                  "type": "short"
                },
                "commented_on": {
                  "type": "text"
                }
              }
            }
          }
        }
      }
    }
    

    将映射更改为Nested类型后,我们可以查询索引的方式略有变化。 我们需要使用Nested查询。
    下面给出了Nested查询示例:

    GET /blog_new/_search?pretty
    {
      "query": {
        "bool": {
          "must": [
            {
              "nested": {
                "path": "comments",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "match": {
                          "comments.name": "john"
                        }
                      },
                      {
                        "match": {
                          "comments.age": 34
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
    

    由于用户{name:john,age:34}没有匹配,上面的查询将不返回任何文档。

    再次感到惊讶? 只需一个小小的改变即可解决问题。
    这可能是我们理解的一个较小的变化,但是在elasticsearch存储我们的文档的方式上有很多变化。
    在内部,嵌套对象将数组中的每个对象索引为单独的隐藏文档,这意味着可以独立于其他对象查询每个嵌套对象。
    下面给出了更改映射后样本文档的内部表示:

    {
      {
        "comments.name":    [ john ],
        "comments.comment": [ after i investing started reading this ],
        "comments.age":     [ 38 ],
        "comments.rating":  [ 9 ],
        "comments.date":    [ 25 Nov 2017 ]
      },
      {
        "comments.name":    [ william ],
        "comments.comment": [ article, nice ],
        "comments.age":     [ 34 ],
        "comments.rating":   [ 8 ],
        "comments.date":    [ 30 Nov 2017 ]
      },
      {
        "comments.name":    [ smith ],
        "comments.comment": [ good, post, very],
        "comments.age":     [ 33 ],
        "comments.rating":   [ 7 ],
        "comments.date":    [ 20 Nov 2017 ]
      },
      {
        "title":            [ invest, money ],
        "body":             [ as, investing, money, please, soon, start ],
        "tags":             [ invest, money ],
        "published_on":     [ 18 Oct 2017 ]
      }
    }
    

    如您所见,每个内部对象都在内部存储为单独的隐藏文档。 这保持了他们的领域之间的关系。

    3、Nested类型的作用?

    从上一小节,可以清晰的看出nested类型的特别之处。
    nested类型是对象数据类型的专用版本,它允许对象数组以可以彼此独立查询的方式进行索引。

    4、Nested类型的适用场景

    图片来自:rockybean教程
    ——图片来自:rockybean教程

    5、Nested类型的增、删、改、查、聚合操作详解

    还是以第2节的blog_new索引示例,Nested类型的增、删、改、查操作。

    5.1 Nested类型——增

    新增blog和评论

    POST blog_new/blog/2
    {
      "title": "Hero",
      "body": "Hero test body...",
      "tags": ["Heros", "happy"],
      "published_on": "6 Oct 2018",
      "comments": [
        {
          "name": "steve",
          "age": 24,
          "rating": 18,
          "comment": "Nice article..",
          "commented_on": "3 Nov 2018"
        }
      ]
    }
    

    5.2 Nested类型——删

    序号为1的评论原来有三条,现在删除John的评论数据,删除后评论数为2条。

    POST  blog_new/blog/1/_update
    {
     "script": {
        "lang": "painless",
        "source": "ctx._source.comments.removeIf(it -> it.name == 'John');"
     }
    }
    

    5.3 Nested类型——改

    将steve评论内容中的age值调整为25,同时调整了评论内容。

    POST blog_new/blog/2/_update
    {
      "script": {
        "source": "for(e in ctx._source.comments){if (e.name == 'steve') {e.age = 25; e.comment= 'very very good article...';}}" 
      }
    }
    

    5.4 Nested类型——查

    如前所述,查询评论字段中评论姓名=William并且评论age=34的blog信息。

    GET /blog_new/_search?pretty
    {
      "query": {
        "bool": {
          "must": [
            {
              "nested": {
                "path": "comments",
                "query": {
                  "bool": {
                    "must": [
                      {
                        "match": {
                          "comments.name": "William"
                        }
                      },
                      {
                        "match": {
                          "comments.age": 34
                        }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
    

    5.5 Nested类型——聚合

    认知前提:nested聚合隶属于聚合分类中的Bucket聚合分类。
    聚合blog_new 中评论者年龄最小的值。

    GET blog_new/_search
    {
      "size": 0,
      "aggs": {
        "comm_aggs": {
          "nested": {
            "path": "comments"
          },
          "aggs": {
            "min_age": {
              "min": {
                "field": "comments.age"
              }
            }
          }
        }
      }
    }
    

    6、小结

    如果您在索引中使用内部对象并做查询操作,请验证内部对象的类型是否为nested类型。 否则查询可能会返回无效的结果文档。
    更新认知是非常痛苦的,不确定的问题只有亲手实践才能检验真知。

    参考:
    [1]http://t.cn/Evwh0uW
    [2]官网6.x+:http://t.cn/Ehltakr
    这里写图片描述
    打造Elasticsearch基础、进阶、实战第一公众号!

    展开全文
  • 1. 报错: ### Cause: java.sql.SQLSyntaxErrorException: ORA-00911: ... nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符 2.出错 原因: 1) sql在数据库执行都是OK的。 真...

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。

     

    1. 报错:

    ### Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
    
    ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
    
    

    2.出错 原因:

    1)  sql在数据库执行都是OK的。  

    真正的原因是: 在mybatis 中sql结尾处多了一个" ; " 去掉就可以了。

    2)  mybatis ,我查出的数据在resultMap中没有对应的映射字段来匹配,查到的结果无法全部填充到对象属性才报错的。

    即:

      SELECT 
                  DISTINCT allData.time AS CREATE_DATE,         
                  allData.FORMAT AS FORMAT,           
                  allData.ORDER_TYPE  AS ORDER_TYPE,
                  allData.ORDER_TYPE_DEC  AS ORDER_TYPE_DEC,
                  allData.ACCOUNT  AS ACCOUNT....

    中FORMAT 对应的 <result property="format" column="FORMAT" jdbcType="INTEGER" />  忘了写了。

     

    展开全文
  • ) nested nested classes are supposed to work.Eclipse Oxygen.3 didn't mention "Object Teams" however I assume the following code exemplifies some anti-pattern since I don't see a bu...

    I'm curious how (if?) nested nested classes are supposed to work.

    Eclipse Oxygen.3 didn't mention "Object Teams" however I assume the following code exemplifies some anti-pattern since I don't see a business need for a nested nested class.

    public class CACCIData {

    ...

    public CompanySearchResultsResult.CompanySearchResult mcCompanySearchResult = null;

    public static class CompanySearchResultsResult {

    public List CompanySearchResult

    = new ArrayList();

    public static class CompanySearchResult {

    // ...

    }

    }

    Eclipse 2018-12 compile error: 'CACCIData$CompanySearchResultsResult' cannot be used as type anchor for an externalized role: is not a team (OTJLD 1.2.2(b)).

    展开全文
  • <div><p>Nested Avro to Nested ORC conversion support: The added code generates queries to create a nested ORC table (without any modification / flattening to Avro table schema) and insert into the ...
  • Normal class(Non-nested class) can only be public, abstract or final.For nested classes, static is allowed.Nested classes(private, public, protected) -> 2 Categories.1. Static Nested Class (Very D....

    Normal class(Non-nested class) can only be public, abstract or final. For nested classes, static is allowed.

    Nested classes(private, public, protected) -> 2 Categories.

    1. Static Nested Class (Very Different from C# static class)

    alpha: Have access to all the static members of its parent class.

    beta: Can instantiate objects by new ParentClass.StaticNestClass(). Now allowed to create objects in C#.

    gamma: Can have non-static members.

    delta: same as gamma. Cannot access ParentClass.this.

    2. Non-static nested class(Inner Class)

    alpha: Have access to all the members of its parent class.

    beta: Can instantiate objects by new ParentClass().new InnerClass().

    gamma: Cannot have static members, except for final static fields.

    delta: Variable shadowing:

    ParentClass.this.memberName -> Parent class member.

    this.memberName, ParentClass.InnerClass.this.memberName  -> Inner class member

    ======================================

    1. Interface can only be defined inside a top-level class, an interface or in static context because interfaces are inherently static.

    2. Anonymous Classes:

    Interface/AbstractClass obj = new Interface/AbstractClass(Empty for interface. Initialize for abstract class){

    String/int ...;

    public void ImplementAbstractMethodA(){...}

    public void ImplementAbstractMethodB(){...}

    };

    展开全文
  • nested exception is org.apache.ibatis.exceptions.PersistenceExceptionCause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection;
  • Caused by: java.lang.IllegalStateException: [nested] nested object under path [subs] is not of nested type <p>Even though the schema defines "es_type" with "nested". <p>Is this a ...
  • Nested Aggregation A special single bucket aggregation that enables aggregating nested documents. 一种特殊的单桶聚合,可聚合嵌套文档。 Reverse nested Aggregation A special single bucket aggregation ...
  • nested classes:1.static nested classes:publicclassOuter{publicclassNested{}}declare inner class:Outer.Nested instance = new Outer.Nested();2.Non-static nested classes(Inner Classes):publicclassO...
  • ES 报错 reason: [nested] nested path [XXXX] is not nested PUT /issues { "mappings": { "properties": { "XXXX": { "type": "nested", "properties": { "username": { "type": "keyword" },
  • The Java programming language allows you to define a class within another class... Such a class is called anested classand is illustrated here:class OuterClass {...class NestedClass {...}}Terminology:...
  • Nested Query support

    2020-11-30 20:29:36
    <div><p>DSL support for nested queries on the already supported nested type. <p>Nested objects/documents allow to map certain sections in the document indexed as nested allowing to query them as if ...
  • <div><p>I have has_one assiociation with nested_attributes enabled. Before including awesome_nested_set everything works just fine. After adding awesome_nested_set the nested attributes for the has_...
  • Nested Dolls

    万次阅读 2017-11-30 09:16:43
    Dilworth is the world’s most prominent collector of Russian nested dolls: he literally has thousands of them! You know, the wooden hollow dolls of different sizes of which the smallest doll is
  • nested exception is java.lang.StackOverflowError”的错误。总结一哈:StackOverflowError通常情况下是死循环或者是循环依赖了。Caused by: java.lang.StackOverflowError at com.hry.seckill.servi...
  • Nested KVM

    2017-12-24 13:13:55
    Nested KVM在Intel处理器上,KVM使用Intel的vmx(virtual machine eXtensions)来提高虚拟机性能,即硬件辅助虚拟化技术。如果一台虚拟机能够和物理机一样支持”vmx”,那么就可以在这台虚拟机上再次安装虚拟机。...
  • <div><p>Like stated in the pull request before, I added some tests for the nested_update functionality. <p>I also included a nested_alter function, which used the advanced nested_update capabilities ...
  • es nested

    2019-01-25 11:57:31
    要想能用父子级联查询 首先 index得设置成 nested 类型,如 PUT my_index { “mappings”: { “_doc”: { "properties": { "manager": { "properties": { "age": { ...
  • <div><p>It should be possible to create a nested exception using the <code>exception</code> and <code>set_backtrace</code> methods on an exception. <p>For example: <pre><code>rb begin begin raise &#...
  • 注:在完成mcn功能的时候,现有的数据结构和方式都不能完成相应的需求,所以通过调研使用nested对象来实现。具体需求:mcn存在主账号和子帐号。同时一个主账号会对应多个子帐号,一个子帐号也会对应多个主账号,存在...
  • C++ nested class

    2020-01-23 15:29:49
    C++ nested classnested class參考連結 nested class 在TensorRT/samples/common/logging.h中,TestAtom被定義在Logger中: class Logger : public nvinfer1::ILogger { public: //! //! \brief Opaque handle ...
  • 版权声明:本文为博主原创文章,无需授权即可转载,甚至无需保留以上版权声明,转载时请务必注明作者。 ...解决——》Handler dispatch ... nested exception is java.lang.NoSuchMethodError1、操作2、现象(错误...
  • 学习慕课上的一个项目,使用的是Spring+...org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: Error querying database. Cause: org.sprin...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 57,732
精华内容 23,092
关键字:

nested