Add field to schema upon search query request in Solr - solr

Is it possible to add fields to the schema (managed or not, does not matter) at search query time?
Basically my Solr will receive search queries for fields that I cannot anticipate. If the query contains a field that is not in the schema, i get :
"msg:undefined field"
I use Distance Function to sort results:
/select?q=city:Atlanta+_val_: dist(2,fieldX,fieldY,0,0)&fl=ticket_id,score&sort=score asc"
For example if fieldY is not in the schema, I would like Solr to give it a default value and not fail

Related

MongoDB with Apache Solr: Should you index entire collection in Solr? If not then how to get the complete document based on solr index search query

I am using apache solr for field based and for full text search as well.
Should I index entire collection of mongodb in Solr?
If i decide to index only selected fields out of a document of mongo collection in apache-solr, then will I be able to get the complete document from indexed search query?
Two of the properties fields can have in Solr are indexed and stored. In a high level simple way, indexed means they are processed and searchable, stored just means their original content is saved as is and can be retrieved. So for example, you can index the entire MongoDB document into a stored Solr field, then index various other parts of the document into indexed fields. So you could search on those indexed fields, and get the entire document back from the stored field in the result.
Note: fields can be both indexed and stored

Solr query searching on non-indexed fields

Solr version 6.1.0
Created a schema with some fields as indexed=true on which I specifically want the solr main-query q to search.
And also added more fields, which I just wanted to select, so marked them as stored=true and indexed=false.
Issue now is that, main query q=India is searching on non-indexed fields like country, which I have specified in the image.
See the result below
It is selecting the non-indexed field only when I specify the full value of non-indexed field.
See result for q=Indi
How can I restrict solr from searching on non-index fields?
According to the screenshot above you're copying the content sent to the field country into the field _text_. When you're not giving Solr a specific field to search (i.e. you're not using one of the dismax handlers with qf or not prefixing your term with the field name field:value), it falls back to the default search field. This is set to _text_ by default. This field is indexed, and since you're copying the content from your country field into the _text_ field, the values from country will give a hit.
If you don't want this to happen, don't copy the content from country into _text_, or give Solr the actual field you want to search.

SolrCloud: Is it possible to get the shard id of a document in the search results

When debugging Solr schema and indexing in a SolrCloud, it is important to easily know into which shard a document was indexed. Is it possible to define a schema field for the shard id such that the automatically assigned shard id is then available in search results?
You dont need to store shard id in your schema explicitly to get it in results. if in fl parameter you add [shard] with other required fields, it will return you the shard id of that document:
/solr/collection_name/select?q=*:*&fl=[shard],*&wt=json&indent=true

Can Solr use field values of a known document in a query?

I would like to perform a Solr search using the values of certain fields of an indexed document which I can identify by its id. With MLT this is somehow possible, but I would prefer a regular query parser. Can I somehow use subqueries to inject the result of a subquery into the main query?
For example, let's say I have indexed information about books into solr, where each document represents a book, with an id, title and author field. At query time I have only the document id availible and I would like to search for books by the same author in a single step. Is this possible without using MLT?
You can use JOIN.
http://HOST:PORT/CORE/select?q={!join from=author to=author}id:<ID>

Solr return file name

I have indexed a couple of documents using solr, now when I perform a search using the admin interface, it returns search results in the XML format.
I am trying to figure out how can I associate a document that I have indexed example: test.pdf with the results that I receive and then serve that document to my user ?
Will solr return to me a unique ID of the document that I index, so that after indexing a document I can store the document along with that UID in my database somewhere and then when the user performs a search solr return the unique ID's of documents that match the search criteria and then I serve them from the database
You will need to add the filename as a stored field. Look at your schema.xml and make sure you declare a field of type string and set the stored attribute to true. By setting stored=true you will ensure that Solr can return the field back in results.
See this page for more information: http://wiki.apache.org/solr/SchemaXml

Resources