I am using Solr 6.6. I am trying atomic updates on a date field. The field is defined in schema as
field name="inventory_update_time" type="date" indexed="true" stored="true" omitNorms="true" multiValued="false" omitTermFreqAndPositions="true"/
and I am firing the curl request as
curl 'localhost:8081/solr/sitename/update' -H 'Content-type:application/json' -d '[{"id":"9988062","inventoryUpdateTime":"2018-07-03T06:29:29Z"}]'
but the date is not getting updated.
any suggestions?
Your field name and your JSON name is not the same. You're not doing atomic updates either, since that would require a "set" command.
Your schema has the field name set as inventory_update_time, but in your JSON structure you're using inventoryUpdateTime as the key.
To actually perform an atomic update:
[
{
"id":"9988062",
"inventory_update_time":{
"set":"2018-07-03T06:29:29Z"
}
}
]
Related
Is there a way to overcome the limitation of Solr
How to add an additional column to the collection that I have already created and have crores of data in it.
To add a new field to an existing schema, you can use the Solr Schema API:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name":"sell_by",
"type":"pdate",
"stored":true }
}' http://localhost:8983/solr/gettingstarted/schema
The type parameter corresponds to the field type you want the new field to have.
If you're using the old schema.xml format, you can add the field type in the XML there:
<field name="sell_by" type="pdate" indexed="true" stored="true"/>
You'll have to reload the configuration for the collection after changing it. If you're using Zookeeper (i.e. you're manually uploading your configuration to Zookeeper), you can use zkCli.sh and downconfig and upconfig to download and upload the configuration set.
After adding the field, you'll have to reindex the documents that should contain the field by submitting them to Solr again, so that the content is added to the field as expected.
I've 10s of fileds defined in my Solr manaed-schema, out of those two are as below:
<field name="isBookmarked" type="boolean" indexed="true" stored="true" required="false" multiValued="false" />
<field name="bookmarkedPathologists" type="string" indexed="true" stored="true" required="false" multiValued="true" />
Now, here I want to set isBookmarked value to 'true' OR'false' if bookmarkedPathologists has SOME value passed while querying on the fly.
Post that I'm sorting on isBookmarked field.
Is it possible? Help anticipated
I struggled a lot and finally got luck to solve my problem using below possible solution.
As on the fly updated changes need to be committed to Solr before getting sorted result on and hence my application which is Solr Client, couldn't get updated/dirty values to sort on, if any.
So I added a Filter Query to my Simple Query Criteria as * exists(query({!v='bookmarkedPathologists:patho'})) : will filter my all(*) results with new on the fly created field named as exists(query({!v='bookmarkedPathologists:patho'})) in JSON response as below:-
:
:
"isBookmarked": false,
"bookmarkedPathologists": [
"patho1"
],
:
:
"_version_": 1582235372763480000,
"exists(query({!v='bookmarkedPathologists:patho'}))": false
Post that I just put sort-order over the same i.e. exists(query({!v='bookmarkedPathologists:patho'})) as exists(query({!v='bookmarkedPathologists:patho'})) asc
So Solr returned sorted response over exists(query({!v='bookmarkedPathologists:patho'})).
Solr Function Query helped me a lot from Function Queries
As I understand you want to update the field while querying the data from it.
SOLR programmed in java language and to interface with SOLR is done using REST kind of services.
And service for search is on:
/solr/<CollectionName>/select
And service for update is on:
/solr/update
So you can`t do both with using same query.
But you want to update externally (using other query) then refer.
In My Solr Collection , I have field of type "Payload" and I wanted to see the value stored in specific document . Can you please suggest if there is any way to get the payload field value using Solr Query ?
I tried putting the field name in "fl" parameter list of Solr query but it does not return me Payload field in the result.
Please advice ?
Make sure field is stored. check in schema.xml file if Payload field is set stored="true"
<field name="Payload" type="text_general" indexed="true" stored="true"/>
if it is set to false, change it to true, restart solr and reindex you content. you see Payload field in your results.
I am new to using Solr , and I have made a new core and copied the default schema.xml to the conf/ folder. The changes I have made is very trivial .
<field name="id" type="string" indexed="true" stored="false" required="true" multiValued="false" />
As you can see, I set the id field to stored=false. As per my understanding, the field id should not be displayed now when I do a query search. But that is not happening. I have tried restarting solr instance, and did the query to index the file again.
curl 'http://localhost:8983/solr/TwitterCore/update/json?commit=true'
--data-binary #$(echo TwitterData_Core_Conf/TwitterText_en_demo.json)
-H 'Content-type:application
As per Solr Wiki , this should have re-indexed my file. However when I run my query again, I still see the Id .
An example of the document returned (this is not the complete JSON node , I just copied some parts ) :
"text": [
"RT #FollowTrainTV: Moonseternity just joined #FollowTrainTV - Watch them stream on http://t.co/oMcOGA51kT"
],
"lang": [
"en"
],
"id": "0a8edfea-68f7-4b05-b370-27b5aba640b7", // I dont want to see this
"_version_": 1512067627994841000
Maybe someone can give me detailed steps on re-indexing.
When you change the schema.xml file and restart the solr-server, the changes only apply for new documents. This means you have to clear the index and re-index all documents (Except at query tokenizer, these changes are active immediately after server restart, but this is not the case here). After re-indexing, the id field should not be visible any more.
Another remark: You don't have to test your queries with curl. When you connect to http://localhost:8983/solr with your web-browser you should find an admin interface there. There you can select a core and test your queries.
Refer to this https://lucene.apache.org/solr/guide/6_6/docvalues.html document.
Non-stored docValues fields will be also returned along with other
stored fields when all fields are
specified to be returned (e.g. “fl=*”) for search queries depending on
the effective value of the useDocValuesAsStored parameter for each
field. For schema versions >= 1.6, the implicit default is
useDocValuesAsStored="true".
The String field type has docValues="true" . That is the reason why it is appearing in the search response.
You can either add the useDocValuesAsStored="false" parameter to the field or you can use a different fieldType, say text_general.
We are using Solr 1.4.
How to delete the documents a month ago?
We are doing something similar where we purge items from one of our indexes, using curl and taking advantage of the timestamp field in the Solr schema.
Here is the curl command that you would issue to delete items older than 30 days (using DateMathParser to calculate based on current day), using the timestamp field in the schema.
curl "http://localhost:8983/solr/update?commit=true" -H "Content-Type: text/xml"
--data-binary "<delete><query>timestamp:[* TO NOW/DAY-30DAYS]</query></delete>"
Of course you will need to change the url to match your solr instance and you may choose to use a different field.
Also here is the field definition for the timestamp field from the schema.xml that comes with the Solr distribution in the example folder.
<field name="timestamp" type="date" indexed="true" stored="true" default="NOW" multiValued="false"/>
You need to POST in order to do deletes but if you use the post.jar from the example folder in the installation it is simply:
java -Ddata=args -Dcommit=yes -jar post.jar "<delete><query>$DateField:[* TO $DateOneMonthAgo]</query></delete>"
where $DateField is the name of the field where the date is stored and $DateOneMonthAgo is the date one month from now (2011-11-09T11:48:00Z)