Search code examples
solrsolrjsolr6

how to extract two json indexed documents separately using solrj or QueryResponse


I have indexed two json documents into Solr, and when I get the response am I recieving both documents - how to differentiate the two documents and store the documents separately?


Solution

  • You need to define a (unique) key when indexing the json-documents - this key being either mandatory or not. This could be done in schema.xml or managed-schema, if not already done. Further on would you have to search for this key in the query for fetching the wanted document.

    This can be compared with querying for a unique primary key in SQL and traditional databases. A tuple/record, uniquely defined by the primary key, would in this scenario be equivalent with the json documents.

    Assuming two documents with respective unique id 1 and 2 - can you fetch document 1 by searching forq=id:1 in the Solr Admin-UI - if you want the document with id 1. I'm afraid I don't know how to do this is Solrj or by QueryResponse.

    Management of where documents are stored in Solr is not supported - it is more or less black-boxed. This should however not be a problem considering your situation as long as you specify the query correctly.