So, reading about an issue on the official documentation, I figured that we can have multivalued field as :
solr.add([
{
"id": "doc_1",
"title": "A test document",
"link": ["baidu.com", "google.com"]
}
Now, I would like to index the docs on both the title and link field, how can I do that? And what is the default field it is indexed on?
Related
Using the example document that Solr has:
{
"ID": "1",
"title": "Solr adds block join support",
"content_type": "parentDocument",
"comments": [{
"ID": "2",
"content": "SolrCloud supports it too!"
},
{
"ID": "3",
"content": "New filter syntax"
}
]
},
When I try to index this json, it would give this error: "ERROR: [doc=1] unknown field 'comments.ID'" even though the field ID is defined in the schema (of course, comments.ID is not)
I am trying to use the labelled relationship and not the anonymous relationship using _childDocuments_ because that is what the docs recommends. What am I missing?
If you're trying to send this to the /update/json/docs convenience path, it will likely fail with a nested document.
Try instead to send your document to the /update path, and use the JSON command structure shown here https://solr.apache.org/guide/8_11/uploading-data-with-index-handlers.html#sending-json-update-commands
Basically, send to /update and wrap your document in an
{
"add": {
"doc": {<your document here>}
}
}
Be sure to also set the content type to application/json
I need to create pivot data by applying filter of two fields i.e city and date range.
Able to filter data by cities and date range but filter is not applying on stats field.
Following is the Solr query that i'm using :
select?&fq={!tag=f1}city:(%221000%20OAKS%22)&facet=true&facet.query=true&facet.query={!tag=queryOne}datadate:[2015-01-01%20TO%202015-12-31]&facet.query={!tag=queryTwo}datadate:[2014-01-01%20TO%202014-12-31]&stats=true&stats.field={!tag=a1%20sum=true%20key=charge1}charge&stats.field={!tag=a2%20sum=true%20key=spend1}spend&facet.pivot={!query=queryOne%20key=c1%20stats=a1}city&facet.pivot={!query=queryTwo%20stats=a2%20key=c2}city&facet=on&indent=on&wt=json&rows=0&q=:
Actual Result :
As you can see, the sum remains same (i.e 2348) regardless of what datadate i m giving in queryone & querytwo tags.
It appears that datadate filters is not having any effect on stats field.
Can anyone please explain what is happening here as i'm pretty new to this.
Thanks in advance.
The problem is that the StatsComponent & FacetComponent are not in perfect integration with each other. The following Solr Jira comprises your use-case: SOLR-6348.
But nevertheless there is work-around for your use-case via JSON Facet API. Here is facet parameter which solves your particular use-case:
{
"date_range": {
"type": "range",
"field": "datadate_dt",
"start": "2014-01-01T00:00:00Z",
"end": "2016-01-01T00:00:00Z",
"gap": "%2B1YEAR",
"facet": {
"cities_and_spends": {
"type": "terms",
"field": "city_s",
"facet": {"sum_of_spend": "sum(spend_d)"}
},
"cities_and_charges": {
"type": "terms",
"field": "city_s",
"facet": {"sum_of_spend": "sum(charge_d)"}
}
}
}
}
Hence the overall GET request would look like:
.../select?indent=on&q=*:*&fq=city:(%221000%20OAKS%22)&rows=0&wt=json&json.facet={%20%22date_range%22:%20{%20%22type%22:%20%22range%22,%20%22field%22:%20%22datadate_dt%22,%20%22start%22:%20%222014-01-01T00:00:00Z%22,%20%22end%22:%20%222016-01-01T00:00:00Z%22,%20%22gap%22:%20%22%2B1YEAR%22,%20%22facet%22:%20{%20%22cities_and_spends%22:%20{%20%22type%22:%20%22terms%22,%20%22field%22:%20%22city_s%22,%20%22facet%22:%20{%22sum_of_spend%22:%20%22sum(spend_d)%22}%20},%20%22cities_and_charges%22:%20{%20%22type%22:%20%22terms%22,%20%22field%22:%20%22city_s%22,%20%22facet%22:%20{%22sum_of_spend%22:%20%22sum(charge_d)%22}%20}%20}%20}%20}
In my instance of Solr 4.10.3 I would like to index JSONs with a nested structure.
Example:
{
"id": "myDoc",
"title": "myTitle"
"nestedDoc": {
"name": "test name"
"nestedAttribute": {
"attr1": "attr1Val"
}
}
}
I am able to store it correctly through the admin interface:
/solr/#/mySchema/documents
and I'm also able to search and retrieve the document.
The problem I'm facing is that when I get the response document from my Solr search, I cannot see the nested attributes. I only see:
{
"id": "myDoc",
"title": "myTitle"
}
Is there a way to include ALL the nested fields in the returned documents?
I tried with : "fl=[child parentFilter=title:myTitle]" but it's not working (ChildDocTransformerFactory from:https://cwiki.apache.org/confluence/display/solr/Transforming+Result+Documents). Is that the right way to do it or is there any other way?
I'm using: Solr 4.10.3!!!!!!
To get returned all the nested structure, you indeed need to use ChildDocTransformerFactor. However, you first need to properly index your documents.
If you just passed your structure as it is, Solr will index them as separate documents and won't know that they're actually connected. If you want to be able to correctly query nested documents, you'll have to pre-process your data structure as described in this post or try using (modifying as needed) a pre-processing script. Unfortunately, including the latest Solr 6.0, there's no nice and smooth solution on indexing and returning nested document structures, so everything is done through "workarounds".
Particularly in your case, you'll need to transform your document structure into this:
{
"type": "parentDoc",
"id": "myDoc",
"title": "myTitle"
"_childDocuments_": [
{
"type": "nestedDoc",
"name": "test name",
"_childDocuments_" :[
{
"type": "nestedAttribute"
"attr1": "attr1Val"
}]
}]
}
Then, the following ChildDocTransformerFactor query will return you all subdocuments (btw, although it says it's available since Solr 4.9, I've actually only seen it in Solr 5.3... so you need to test):
q=title:myTitle&fl=*,[child parentFilter=type:parentDoc limit=50]
Note, although it returns all nested documents, the returned document structure will be flattend (alas!), i.e., you'll get:
{
"type": "parentDoc",
"id": "myDoc",
"title": "myTitle"
"_childDocuments_": [
{
"type": "nestedDoc",
"name": "test name"
},
{
"type": "nestedAttribute"
"attr1": "attr1Val"
}]
}
Probably, not really what you've expected but... this is the unfortunate Solr's behavior that will be fixed in a nearest future release.
You can put
q={!parent which=}
and in fl field :"fl=*,[child parentFilter=title:myTitle].
It will give you all parent field and children field of title:mytitle
Is it possible to define which part of the text in which of the indexed text fields matches the query?
No, as far as I know and can tell from the Jira, no such feature exists currently. You can, of course, attempt to highlight the parts of the text yourself, but that requires to implement the highlighting and also implement the stemming according to the rules applied by MongoDB.
The whole feature is somewhat complicated - even consuming it - as can be seen from the respective elasticsearch documentation.
Refer to Mongodb Doc Highlighting
db.fruit.aggregate([
{
$searchBeta: {
"search": {
"path": "description",
"query": ["variety", "bunch"]
},
"highlight": {
"path": "description"
}
}
},
{
$project: {
"description": 1,
"_id": 0,
"highlights": { "$meta": "searchHighlights" }
}
}
])
I'm afraid that solution applies only to MongoDB Atlas at the moment #LF00.
I'm pretty new to Solr, I'm trying to add a multi-value field with boost values defined for each value, all defined via JSON. In other words, I'd like this to work:
[{ "id": "ID1000",
"tag": [
{ "boost": 1, "value": "A test value" },
{ "boost": 2, "value": "A boosted value" } ]
}]
I know how to do that in XML (multiple <field name = 'tag' boost = '...'>), but the JSON code above doesn't work, the server says "Error parsing JSON field value. Unexpected OBJECT_START". Has Solr a limit/bug?
PS: I fixed the originally-missing ']' and that's not the problem.
EDIT: It seems the way to go should be payloads (http://wiki.apache.org/solr/Payloads), but I couldn't make them to work on Solr (followed this: http://sujitpal.blogspot.co.uk/2011/01/payloads-with-solr.html). Leaving the question open to see if someone can further help.
Found the following sentence in the from the Solr Relevancy FAQ - Query Elevation Component section
An Index-time boost on a value of a multiValued field applies to all values for that field.
I do not think adding an individual boost to each value in the multivalued field is going to work. I know that the Xml will allow it, but I would guess that it may only apply the boost value from the last value applied to the field.
So based on that I would change the Json to the following and see if that works.
[
{
"id": "ID1000",
"tag": {
"boost": 2,
"value": [ "A test value", "A boosted value"]
}
}
]
The JSON seems to be invalid missing a closing ]
[
{
"id": "ID1000",
"tag": [
{
"boost": 1,
"value": "A test value"
},
{
"boost": 2,
"value": "A boosted value"
}
]
}
]
You hit an edge case. You can have the boosts on single values and you can have an array of values. But not one inside another (from my reading of Solr 4.1 source code)
That might be something to create as an enhancement request.
If you are generating that JSON by hand, you can try:
"tag": { "boost": 1, "value": "A test value" },
"tag": { "boost": 2, "value": "A boosted value" }
I believe Sols will merge the values then. But if you are generating it via a framework, it will most likely disallow or override multiple object property names (tag here).
The error has nothing to do with boosting.
I get the same error with a very simple json doc.
No luck solving it.
see Solr errors when trying to parse a collection: Error parsing JSON field value. Unexp ected OBJECT_START
I hit the same error message. Actually the error message was misplaced. The underlying real error was the two of the required fields as per schema.xml in solr configuration were missing in the json payload.
An error message of the kind "required parameters are missing in the document" would have been more helpful here. You might want to check if some required fields are missing in the json payload.