I have data in which field have following java data types.
What would be the best way to index such kind of data.
Thanks,
field_a map<string,string>
field b map<string,array<string>>
How to define schema.xml for it
Currently Solr doesn't support map type field type. So, you can not query on some particular key inside the map and retrieve its value. I don't know whether it'll be helpful you or not, but I can suggest you a way to keep this in Solr.
You can store the map in a field as a json formatted string. Say, document1 has map1 in field_a and document2 has map2 in field_a. Now, you keep some distinct data related to each map to their corresponding documents. When you want to query, query on those fields in stead of the maps. Then in the search result, when you retrieve the json formatted string, parse it in your application and get the values.
Hope this will help.
Related
I would like to create an output based on the field-names of my Solr index objects.
What I have are objects like this e.g.:
{
"Id":"ID12345678",
"GroupKey":"Beta",
"PricePackage":5796.0,
"PriceCoupon":5316.0,
"PriceMin":5316.0
}
Whereby the Price* fields may vary from object to object, some might have more than three of those, some less, however they would be always prefixed with Price.
How can I query Solr to get a list with all field-names prefixed by Price?
I've looked into filters, facets but could not find any clue on how to do this, as all examples - e.g. regex facet - are in regard to the field-value, not the field-name itself. Or at least I could not adapt it to that.
You can get a comma separated list of all existing field names if you query for 0 documents and use the csv response writer (wt parameter) to generate the field name list.
For example if you request /solr/collection/select?q=*:*&wt=csv you get a list of all fields. If you only want fields prefixed with Price you could also add the field list parameter (fl) to limit the fields.
So the request to /solr/collection/select?q=*:*&wt=csv&fl=Price*should return the following response:
PricePackage,PriceCoupon,PriceMin
With this solution you get all fields existing including dynamic fields.
I have a field in solr of type list of texts.
field1:{"key1:val1,key2:val2,key3:val3", "key1:val1,key2:val2"}
I want to form a query such that when I search for key1:val1 and key3:val3 I get the result who has both the strings i.e key1:val1 and key3:val3.
How shall I form the query?
If these are values in a multivalued field, you can't - directly. You'll have to use something like highlighting to tell you where Solr matched it.
There is no way to tell Solr "I only want the value that matched inside this set of values".
If this is a necessary way to query your index, index the values as separate documents instead in a separate collection. In that case you'd have to documents instead, one with field1:"key1:val1,key2:val2,key3:val3" and one with key1:val1,key2:val2.
You can use AND with fq.
Like:
fq=key1:val1 AND key3:val3
With this filter query you will get only records where key1 = val1 AND key3 = val3.
I want to perform a comparison based on one field in a Solr document before it is sent to the Writer or to the user. I want to have the final result object, probably SolrDocumentList, so that I can loop through all the SolrDocument objects and perform a field to field comparison. For instance, if my search returns 10 documents and 5 documents have myfield="myValue", my final list should contain 6 documents with only one document having myfield="myValue", the other 4 documents should be discarded, regardless of what the other fields' contents are.
Is there any plugin for this?
If not, where should I place my code?
You can use Result Grouping / Field Collapsing. Try some thing like this: &q=solr+memory&group=true&group.field=manu_exact&group.main=true
More documenation here: http://wiki.apache.org/solr/FieldCollapsing
I have field string field 'tags' and I want to list all indexed values for 'tag' from Solr.
Is there some introspection API in order to get hold of all values as JSON or XML?
You can use TermsComponent.
The TermsComponent SearchComponent is a simple component that provides access to the indexed terms in a field and the number of documents that match each term.
This will return all the indexed terms. You can specify the field for which you want to retrieve the terms for.
http://localhost:8983/solr/terms?terms.fl=tag&terms.sort=index
does anyone know how to create a custom field in solr 1.4? I need to create a field containing sub values of the same type, say 3 strings.
The problem is abt something like this: suppose i want to declare in the schema an "image" field, which has 3 sub-fields (strings) like "path", "title", "thumb_path".
Any ideas?
I know in solr 1.5 there will be probably the concept of LatLon object, to contain the 2 values -doubles- of latitude and longitude. Have you seen something like that?
Luca
Sounds like you should consider creating an index of "image" documents in your SOLR index.
Each image "doc" would have the fields:
title
path
thumb_path
[gallery]
where [gallery] is a multi-value field (assuming images can appear in more than one gallery)
To construct a gallery page, you run the query "gallery:foo" and then iterate over the list of images, populating the HTML elements from the fields: title, path, etc.
Note: SOLR does not limit you to having a single document type in its index (whether its best practice is another matter). So you could also index other non-image documents as well. In this case its advisable to have a field like "doc_type" so you can limit searches to that type