Search in json nested fields (schema + query) - solr

I got the following JSON stored in a Riak bucket which handle Solr research.
{
"date" : 1535673489,
"customer" : {
"name" : "X"
"id" : 1205643
}
}
And my schema.xml fields look like that for the moment
<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="date" type="int" indexed="true" stored="true" mult iValued="true"/>
And the research on date works perfectly fine with query as
$RIAK_HOST/search/query/order?wt=json&q=date:[1535553489%20TO%201535599999]
Unfortunately I didn't found any documentation that explains how to properly field and query on sub field as customer.name or customer.id
Edit: As I found on the following post Riak search schema and nested fields, it seems that I need to create the fields as follow:
<field name="customer_name" type="string" indexed="true" stored="true" mult iValued="true"/>
But then when I query on the fields, I got no answer to my request
Edit 2: I proceed to the following experimentation and I get no error from riak.
I uploaded the file
{
"customer_name" : "toto",
"customer" : {
"name" : "tata"
}
}
And on research Riak obtained the result from the field "toto" and not the one from "tata". Is it possible that the nesting research is unactivated or associated to another character?

The fields you need to add to your schema.xml are as follows:
<field name="date" type="string" indexed="true" stored="true"/>
<field name="customer" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="customer.name" type="string" indexed="true" stored="true"/>
<field name="customer.id" type="string" indexed="true" stored="true"/>
And then you need to query your index as follow:
$RIAK_HOST/search/query/order?wt=json&q=customer.name:t*

Related

Solr Admin server - basic query request not returning results

I'm new to Solr and the Solrnet technology; I'm stumped with what seems to be something very basic; I haven't found any assistance on searching on the web.
I'm using Solr 8.1 and Solrnet 1.0.19
Using the Solr Admin console I'm able to query using the wildcard (*:*). However using a string that I know is in a document returns num found:0 (I have also been unsuccessful querying from the code).
Here's the code to index and delete my documents:
List<Course> eItems = JsonConvert.DeserializeObject<List<Course>>(File.ReadAllText(#"C:\PathTo\jsonFile\AllItems.json"));
try
{
var solr = SolrInstance.LocateSolrServer();
solr.Delete(SolrQuery.All);
solr.Commit();
foreach (Item eItem in eItems)
{
solr.Add(eItem);
}
//commit to the solr engine
solr.Commit();
I've added <schemaFactory class="ClassicIndexSchemaFactory"/> to the default solrconfig.xml.
I'm also using the default schema.xml file, I've just added my own fields:
<field name="idofitem" type="string" indexed="true" stored="true" required="false" multiValued="false" ></field>
<field name="titleofitem" type="text_general" indexed="true" stored="true" required="false" multiValued="false" ></field>
<field name="urlofitem" type="text_general" indexed="true" stored="true" required="false" multiValued="false" />
<field name="subjectofitem" type="text_general" indexed="true" stored="true" required="false" multiValued="false" />
<uniqueKey>idofitem</uniqueKey>
I've been unable to get past this problem; please if anyone has any suggestions...I'm stumped.

Solr Stats on Tuple

I'm trying to use the Stats Component in my Datastax Solr instance.
The part of the schema I'm trying to get stats on looks like this:
<field name="foo" type="tuple" indexed="true" stored="true"/>
<field name="foo.start" type="bigint" indexed="false" stored="true"/>
<field name="foo.end" type="bigint" indexed="false" stored="true"/>
<field name="foo.time" type="int" indexed="true" stored="true"/>
However, when I try and use stats=true&stats.field={!tuple}foo.time with a *:* query I get the following:
"stats": {
"stats_fields": {
"foo.time": null
}
}
Is it not possible to use a {!tuple} for stats?
This is currently not supported unfortunately. Still you may contact Datastax support for further info.

How to write nested schema.xml in solr?

How to write nested schema.xml in solr
The document in schema.xml says
<!-- points to the root document of a block of nested documents. Required for nested
document support, may be removed otherwise
-->
<field name="_root_" type="string" indexed="true" stored="false"/>
http://svn.apache.org/viewvc/lucene/dev/trunk/solr/example/solr/collection1/conf/schema.xml?view=markup
Which can be used in
https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-BlockJoinQueryParsers
What will be schema.xml for nesting the following items:
Person string
Address
city string
postcode string
I know this is an old question, but I ran into a similar issue. Modifying my solution for yours, the fields you need to add to your schema.xml are as follows:
<field name="person" type="string" indexed="true" stored="true" />
<field name="address" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="address.city" type="string" indexed="true" stored="true" />
<field name="address.postcode" type="string" indexed="true" stored="true" />
Then when you run it you should be able to add the following JSON to your Solr instance and see the matching output in the query:
{
"person": "John Smith",
"address": {
"city": "San Diego",
"postcode": 92093
}
}

Multiple Indexes in same Solr Core..?

I am using Apache Solr..I have the following Scenario.. :
I have Two table in my PostGreSQL database. One is "Cars". Other is "Dealers"
Now i have a data-config file for Cars like the following :
<document name="offerings">
<entity name="jc_offerings" query="select * from jc_offerings" >
<field column="id" name="id" />
<field column="name" name="name" />
<field column="display_name" name="display_name" />
<field column="extra" name="extra" />
</entity>
</document>
I have a similar data--config.xml for "Dealers". It has the same fields as Cars : name, extra etc
Now in my Schema.xml , i have defined the following fields :
<fields>
<field name="id" type="string" indexed="true" />
<field name="name" type="name" indexed="true" />
<field name="extra" type="extra" indexed="true" />
<field name="CarsText" type="text_general" indexed="true"
stored="true" multiValued="true"/>
</fields>
<uniqueKey>id</uniqueKey>
<defaultSearchField>CarsText</defaultSearchField>
<copyField source="name" dest="CarsText"/>
<copyField source="extra" dest="CarsText"/>
Now i want to search like : "where name is Maruti"..So how will Solr know Whether to Search ::: Cars Field : name OR Dealer Field "name"..??
I have read to the following link : http://wiki.apache.org/solr/MultipleIndexes
But i am not able to understand how is works..??
After reading that link : I made another field in My Cars and Dealers *data-config.xml* .. Something like :
<field name="type" value="car" /> : in Cars date-config.xml
and
<field name="type" value="dealer" /> : in Cars date-config.xml
And then in Schema.xml i created a new field :
<field name="type" type="string" indexed="true" stored="true" />
And then i queried something like :
localhost:8983/solr/select?q=name:Maruti&fq=type:dealer
But it dint Worked..!!
So what should i do..??
if the fields are the same for both cars and dealers, you could use one index with an object defined like so:
<fields>
<field name="id" type="string" indexed="true" stored="true"/>
<field name="name" type="name" indexed="true" stored="true" />
<field name="extra" type="extra" indexed="true" stored="true" />
<field name="description_text" type="text_general" indexed="true" stored="true" multiValued="true"/>
<field name="type" type="string" indexed="true" stored="true" />
</fields>
this will work for both cars and dealers (so you don't need to have 2 indexes) and you'll use the "type" field to sort out if you want a "dealer" or a "car" (i'm using the same system to filter out similar types of objects with only a minor "semanthical" difference)
also you'll need to add stored="true" to the fields you want to retrieve, or you'll be only able to use them for searching (hence that index="true")
Adding a default value to the type field will ensure the type value being set to cars|dealer.
You will have to index the sources separately. Then use copy field and you can easily filter on either cars|dealer.
This does seem a bit tricky and is not explained well in the muti-indexes link referred to above.

Solr with String and Text filed Queries .?

<field name="NAME" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="NAMETEXT" type="text" indexed="true" stored="true" multiValued="true"/>
My Search Query is
NAME:22
NAMETEXT:22 both query i tried.. It returns results with name
"index 2.2", "indexch 2.2", index3 2.2
Why its returning this values..
Because your WordDelimiter converts "2.2" into "22" and these terms are matched with your query.

Resources