在Lucene索引之间存储和检索Json对象 [英] Storing and retrieving Json object to/from lucene indexes

查看:294
本文介绍了在Lucene索引之间存储和检索Json对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将一组json对象存储到lucene索引中,并且还想从索引中检索它。我正在使用lucene-3.4。

I have store a set of json object into the lucene indexes and also want to retrieve it from the index. I am using lucene-3.4.

那么在lucene中是否有任何库或简单的机制可以实现这一目标。

So is there any library or easy mechanism to make this happen in lucene.

例如:Json对象

{
    BOOKNAME1: {
        id:1,
        name:"bname1",
        price:"p1"
    },
    BOOKNAME2: {
        id:2,
        name:"bname2",
        price:"p2"
    },
    BOOKNAME3: {
        id:3,
        name:"bname3",
        price:"p3"
    }
}

任何帮助将不胜感激。
预先感谢,

Any sort of help will be appreciated. Thanks in advance,

推荐答案

如果您不想在json中搜索而只存储它,则可以只需提取ID,希望该ID是唯一的。然后您的Lucene文档将具有两个字段:

If you don't want to search within the json but only store it, you just need to extract the id, which will hopefully be unique. Then your lucene document would have two fields:


  • id(已索引,不一定存储)

  • json本身(仅存储)

将json存储在Lucene中后,您可以按ID过滤检索它。

Once you stored your json in lucene you can retrieve it filtering by id.

另一方面,这几乎是 elasticsearch 处理您的文件。您只需通过REST API向其发送一些json。 elasticsearch会保留json的原样,并且默认情况下也使其可搜索。这意味着您可以直接通过id检索json或对其进行搜索,而无需编写任何代码。

On the other hand this is pretty much what elasticsearch does with your documents. You just send some json to it via a REST api. elasticsearch will keep the json as it is and also make it searchable by default. That means you can either retrieve the json by id or search against it, out of the box without having to write any code.

此外,使用Lucene,在提交文档或重新打开索引阅读器之前,您的文档将不可用,而elasticsearch会向其中添加方便的事务日志,以便获取始终是实时的。

Also, with lucene your documents wouldn't be available till you commit your documents or reopen the index reader, while elasticsearch adds a handy transaction log to it, so that the GET is always real time.

此外,elasticsearch还提供了更多功能:完善的分布式基础架构,构面,脚本等。看看!

Also, elasticsearch offers a lot more: a nice distributed infrastructure, faceting, scripting and more. Check it out!

这篇关于在Lucene索引之间存储和检索Json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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