【问题标题】:What is the role of @Indexable in elasticsearch-osem?@Indexable 在 elasticsearch-osem 中的作用是什么?
【发布时间】:2012-02-05 20:53:41
【问题描述】:

我正在考虑将 elasticsearch 集成到我的 spring-jpa 驱动的应用程序中。
为此,elasticsearch-osem 项目似乎非常适合。
我无法理解的是@Indexable(indexName = "someIndex")注解的作用,如项目介绍中的示例所示。
让我困惑的是,在同一个例子中它说:

然后您可以将对象写入 ElasticSearch 客户端:
node.client().prepareIndex("twitter", "tweet","1").setSource(context.write(tweet)).execute().actionGet();

其中“twitter”是索引名称。

我认为我的问题是为什么还要在字段上定义@Indexable 以及为什么要定义索引名称?

谢谢

【问题讨论】:

  • 你对这个项目有好运吗?它对你有用吗?我想和你谈谈,在 gearondATsbcglobal.net
  • @Dennis 我最终在没有该项目的情况下工作。主要是因为我意识到关系文档的差距不是它可以为我解决的,但我必须自己解决。

标签: java elasticsearch


【解决方案1】:

@Indexable 表示索引中应包含哪些字段。 indexName 是索引中字段的名称。这不是您在其他调用中设置的索引名称。

来自 Javadoc:

/**
* The name of the field that will be stored in the index. Defaults to the property/field name.
*/
    String indexName() default "";

【讨论】:

  • 您好 ynka,感谢您的回答。所以你认为这只是一种允许字段别名的机制吗?我以后可以查询这些字段的索引吗?
  • 我不认为它只是允许别名。我认为当您不使用“@Indexable”时,您将无法在搜索索引时使用该字段。但请记住,我在工作中使用 lucene ;)
  • (或者可以用,但是会很慢)
  • 实际上我查看了源代码,它允许索引实体本身不可搜索的属性。我会添加一个详细的答案。
【解决方案2】:

查看源代码后,我发现@Indexable 用于为索引实体中的索引属性的字段提供别名以允许对未索引中的属性进行索引实体。 您可以在 AttributeSourceImpl 类型的 getIndexableProperties 方法中看到这一点,它在评论中说:

可搜索的类属性是隐式可索引的

【讨论】:

    猜你喜欢
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 2017-02-08
    • 2013-02-08
    • 2018-08-01
    • 2019-05-01
    • 2019-01-16
    • 2016-08-07
    相关资源
    最近更新 更多