Tahil Bansal
Tahil Bansal

Reputation: 163

Finding the exact failing field with ID in Lucene

I have a structured JSON data in the following form:

field1:{
  "id" : "123",
  "field2" : [
    {
     "id" : "345",
     "type" : "ABC"
    },
    {
     "id" : "456",
     "type" : "XYZ"
    },
   ]
}
  

I'm converting this JSON into lucene document as

field1.id : 123
field1.field2.id : 345
field1.field2.type: ABC 
field1.field2.id : 456
field1.field2.type: XYZ

I've a query which states that type should be equal to ABC i.e +field1.field2.type: ABC. I need to find the exact id for the field failing, in this case.. 123->345. How can I achieve that ?

I cannot store the id in the field like field1.123.field2.456.type - it is not possible. Is there any possible way to do with SortedSetDocValuesField or FeatureField. Anything that lucene provides to store the id attached with the value for a specific field.

Upvotes: -1

Views: 84

Answers (2)

Anatoliy Kostyuk
Anatoliy Kostyuk

Reputation: 76

not sure that i get it (not enough information). As i see you can add combined uid: field2_path: 123_345 (so each sub object in array can contains part of parent document id and also own id). plus "_" deliminator can give yuo possibility to restore document id.

another variant: field2_id: can be multiple field value, so it can contains both "parent id" and "own id". to know which id is related to which level of structure - prefix can be added. So lucene document should contains two fields with same name: field2_id = 0_123 field2_id = 1_345

as i said it is not well known - structure of document; search query (result to achieve

Upvotes: 0

Hadjer CHETTAB
Hadjer CHETTAB

Reputation: 23

For me, field2 is an array of objects so the right conversion would be ( or an equivalent) :

field1.id : 123
field1.field2[0].id : 345
field1.field2[0].type: ABC 
field1.field2[1].id : 456
field1.field2[1].type: XYZ

Can you add your code so we can analyse better please

Upvotes: 0

Related Questions