当前位置: 首页 > 知识库问答 >
问题:

Elasticsearch 6.4.2中的Spring数据不适用于Java hashmap属性

冯澄邈
2023-03-14

@document(createIndex=true,indexName=“djacence”,type=“djacence”)公共类djacencyDoc{

@Field(type = FieldType.Object)
    private Agent agent1 = null;
}

类代理{prop6:480 prop7:类FAttributes7{attr1Name:[类FAttributes{dscp:12 txinterval:100 padding:425},类FAttributes{dscp:14 txinterval:100 padding:425}]}listips:类RProperties{attproperties:{prasanta3=类attproperties{attproperties:{prasanta3=class AttProperty{ip:192.168.57.39 Agent:PRASANTA1 dstid:PRASANTA2}}

 Here "listIps" value is "RProperties" which is a Java Hashmap ,Before save it has some value but While saving into elasticsearch RProperties value is saved as null.
Agent: class Agent2 {
        prop1: true
        prop2: 50000
        prop3: 50000
        prop4: 300
        prop5: null
        prop6: 480
        prop7: class Agent3 {
            attr1Name : [class FAttributes {
                dscp: 12
                txInterval: 100
                padding: 425
            }, class FAttributes {
                dscp: 14
                txInterval: 100
                padding: 425
            }]
        }
        listIps: class RProperties {
            RProperties: null
        }
        iIp: 192.168.57.53
        sunet: 255.255.255.78
        gway: 192.168.57.187
        testId: null
        van: 0
        vriority: 0
        phyId: p1
    }
    sContinuity: null
    ip: null
    nQuality: null
}

Why for hashmap properties  "RProperties" elasticseach saves null ? The above document is saving correctly when i am using postman or curl, But from my SpringBoot Application using Spring DATA it is not working .

共有1个答案

田宇
2023-03-14
listIps:class RProperties{  
   attProperties:{  
      PRASANTA3=class AttProperty{  
         Ip:192.168.57.39;
         Agent:PRASANTA1 ;
         dstId:PRASANTA2
      }
   }
}

The above code should be like below format,

listIps:class RProperties extends HashMap<String,AttProperty>{       
      "PRASANTA3"=class AttProperty{  
         Ip:192.168.57.39;
         Agent:PRASANTA1 ;
         dstId:PRASANTA2
      }
}


Here RProperties class should extends from Hashmap , instead of RProperties contains one more class (AttProperties) which again contains the hashmap properties.

Here RProperties is a HashMap which contains key("PRASANTA3"),value(AttProperty class values) .
 类似资料:
  • 我们在Spring启动应用程序中使用多个数据源配置。这两个数据源都只属于 mysql。 使用以下配置多个数据源: https://medium . com/@ Joe clever/using-multiple-data sources-with-spring-boot-and-spring-data-6430 b 00 c 02e 7 pom.xml更改: 当我启动应用程序时,默认情况下,它会创

  • 我目前正在使用带有Spring Data commons 1.9.1和Spring JPA 1.7.1的JpaSort。我需要使用QueryDSL,因为JPA不允许为空值定义排序。 这是我的存储库 我在我的控制器中这样做: 这就是我对JPA的看法: 这是我为QueryDSL更改的内容: 然而,似乎什么都没有得到整理。我已经启用了调试日志记录,我看到了这一点: 如果我将其更改为: 然后,按我的“数据

  • 当应用程序基于Spring Boot时,不考虑定义的实体图。相反,在JUnit测试期间,一切正常。 领域非常简单:书籍及其类别(多对多关系) 图书类: 类别类: 带有使用创建的实体图的方法的JPA存储库: REST控制器中的用法: 启动Spring Boot(mvn Spring Boot:run)并导航到http://localhost:8080/books书籍会被显示,但它们有各自的类别(由于

  • 当使用Spring的RestTemplate将一些JSON响应反序列化为对象时,我没有这样做,因为我使用了Kotlin数据类作为对象模型。 这是数据类: 我使用这些依赖项: 执行涉及RestTemboard逻辑的单元测试时的错误消息: 原因:com.fasterxml.jackson.databind.exc.无效定义异常:无法构造的实例(没有Creator,如默认构造,存在):无法从Object

  • 我试图初始化log4j记录器使用SpringIOC和使用财产onfigurator.configure配置记录器,但财产onfigurator.configure不工作。 我的问题是如何将配置(log4j.properties)传递给Logger类? 波姆。xml 混淆班 log4j。性质

  • 问题内容: 我正在做.. 现在在我的@Configuration文件中,如果执行此操作,则不会获取SpringConfig.properties中存在的属性… 但是如果我使用该财产 我什至尝试添加更多这样的行,但是没有用。 有人知道为什么我的属性未加载到环境中吗?谢谢。 问题答案: PropertySourcesPlaceholderConfigurer直接读取属性文件(就像在Spring 3.0

  • 我有3个实体大学,学生和学科。大学和学生有多对多的关系,学生和学科也有多对多的关系。它们的实施如下。大学: 学生: 主题: 现在,我想为某所大学招收学生。但不包括相关主题。因此,我按如下方式调用存储库: 但是,这是返回我的学生名单以及相关科目也从科目。似乎当我叫u.get学生()的时候,它不仅是在吸引学生,也在吸引科目,尽管FetchType是懒惰的。 请建议。 编辑:UniversityRepo

  • 问题内容: 嗨,我正在用React钩子编程一个页面,并且试图将从服务器获取的数据设置为状态。怎么它不起作用。我从服务器获取数据,但无法将其映射到状态。任何想法可能是什么问题? 来自服务器的数据 问题答案: 是async方法,因此您将无法在其下获取更新的数据。 否则您的代码是好的,如果您循环并显示它,它将反映在DOM中 运行下面的代码片段,并检查HTML和console两者,这将清除流程。