New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested Documents #89
Comments
The One obvious disadvantage to this approach is the fact that stringifying sub-documents makes the inner fields unindexable in Solr. Mongo Connector should flatten the documents to provide a way to index those fields. I'm marking this as a bug and will use this issue to track progress. Thanks for pointing this out, @Crossener! |
My query output in solr is:
What I should do if I want to index fields from subdocuments? Do have to do flattens the structure of embedded documents? |
Hi @Crossener, Flattening the document would allow the inner fields to be indexed. There isn't a way to index the inner fields when they're in the string-ified Python dictionary form. I have a patch in code review right now to address this issue, and I should have it pushed in the next few days. If you need a more immediate fix, try adding the following at the very beginning of the
This change will flatten your nested documents so that a document that looks like this in MongoDB:
will now look like this in Solr:
Note that this requires the definition of two new fields in |
Many thx, what happened if there are arrays, e.g.
|
resolved by commit 2ecf3b6. This includes unwinding arrays so that sub-documents can be flattened. See this comment for |
Awesome! |
Thx a lot. |
Thanks for the solution guys... my only problem is the "index" included in the field names for the arrays which restricts how I configure my fields to be indexed in Solr. Here's an example of what I have: {
"a": 0,
"b": [
{
"c": 6,
"d": "six"
},
{
"c": 7,
"d": "seven"
},
{
"c": 8,
"d": "eight"
}
]
} I'm forced to configure dynamic fields that look like: <dynamicField name="b.*" type="string" indexed="true" stored="true"/> I want to be able to do something like this: <dynamicField name="b.c.*" type="int" indexed="true" stored="true"/>
<dynamicField name="b.d.*" type="string" indexed="true" stored="true"/>
<!-- OR -->
<field name="b.c" type="int" indexed="true" stored="true" multiValued="true" />
<field name="b.d" type="string" indexed="true" stored="true" multiValued="true" /> Let me know if there is something I'm doing wrong or missing. Thanks. |
There isn't a very easy way to deal with that schema. Your example document will look like the following after going through Mongo Connector:
You do have a few options:
I'm sorry that the transformation isn't super-helpful to you. It's difficult to find a good solution for flattening a MongoDB document, given that arrays may contain any mixture of data types. |
Thanks @lovett89, I totally understand what you're saying. I don't know how many items will be in the array and it will be a lot of effort to change the mongo structure at this point. I may try to tinker with the code a bit to see if I can get the list index at end. I'm considering adding an additional param to "flattened_kernel" method for the index, where I only add it and pop it back if there's a value. It may work for my case, but I don't know if it would be best as a general solution. Will let you know how it works out. |
Any fix yet for this issue .I am facing the same problem |
@suja-arun, Please see #99. |
Hi,I saw that ,but I have array of objects as given below . This is my Schema <dynamicField name="Contributor.*" type="string" indexed="true"
stored="true" /> And the data I am trying to Insert is But this is not inserting anything to solr for contributor . |
Hi , I need some help on the following.I have data as follows
I need only the publisher name from above <dynamicField name="Publisher*" type="string" indexed="true"
stored="true" multiValued="true" />
<field name="pname" type="string_lowercase" indexed="true"
stored="true" multiValued="true"/>
<copyField source="Publisher*" dest="pname" /> I get the following Document
How ever i need only the Publisher.PublisherName and I need to facet on the same. How can I accomplish this .On defining the dynamic field as Much Appreciate help on this topic |
Hey, hope this help. try this.
|
Hi , Thanks for your response, but this does not seem to work What are other options? |
I assumed that would create Publisher.PublisherName.0, Publisher.PublisherName.1, etc and the copyField would catch it. Is it instead creating Publisher.0.PublisherName, Publisher.1.PublisherName? If so, maybe change the source copyField to be *.PublisherName. I believe the wild card and go on the beginning or end of the dynamic field name in solr. Tim |
Hi, <dynamicField name="Publisher.PublisherName*" type="string" indexed="true"
stored="true" multiValued="false" />
<field name="pname" type="string_lowercase" indexed="true"
stored="true" multiValued="true"/>
<copyField source="Publisher.PublisherName*" dest="pname" /> <dynamicField name="*.PublisherName" type="string" indexed="true"
stored="true" multiValued="false" />
<field name="pname" type="string_lowercase" indexed="true"
stored="true" multiValued="true"/>
<copyField source="*.PublisherName" dest="pname" /> No Data in both cases in pname or dynamic field. |
@suja-arun @acmeinternetsolutions |
Thank you.This is working as expected. Perfect !! |
Hi, is it possible to keep existing structure in MongoDB for Solr? Solr supports multivalues so I have an array in Mongo and expect Solr to insert array as well, copyField solution is not an option for me because I have a lot of dynamic fields and I can't define all fields in my schema.xml. So it's really critical to have ability to insert arrays like: |
Hi Anna, Mongo Connector automatically unwinds arrays. For the rationale behind
|
How to use mongo connector to indexing fields of embedded documents for solr? For example the field StreetName of:
The manual says the connector flattens the nested documents but in solr I cant see the flatted field StreetName.
The text was updated successfully, but these errors were encountered: