Storing and retrieving Json object to/from lucene indexes

elasticsearch, java, lucene

Solution

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:

- the id (indexed, not necessarily stored)

- the json itself, as it is (only stored)

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

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.

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.

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

Problem

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. So is there any library or easy mechanism to make this happen in lucene. For sample: Json object ``` { 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,

Original source