changing the type of id from string to uuid in solr 7.2+ - windows

I have created an example SolrCloud instance using example Settings in Solr 7.2.1 on windows:
bin/solr start -e cloud
bin/solr.cmd create -c trans -s 2 -rf 2
Then I updated the schema (as most of the data will come from Postgres and SQL Server:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
"name":"trans",
"type":"string",
"stored":true,
"indexed":true},
"add-field":{
"name":"t",
"type":"pdate",
"stored":true,
"indexed":true},
"add-field":{
"name":"l",
"type":"pint",
"stored":true,
"indexed":true},
}' http://localhost:8983/solr/trans/schema
which results into the following schema:
curl http://localhost:8983/solr/trans/schema/fields
{
"responseHeader":{
"status":0,
"QTime":0},
"fields":[{
"name":"_root_",
"type":"string",
"docValues":false,
"indexed":true,
"stored":false},
{
"name":"_text_",
"type":"text_general",
"multiValued":true,
"indexed":true,
"stored":false},
{
"name":"_version_",
"type":"plong",
"indexed":false,
"stored":false},
{
"name":"id",
"type":"string",
"multiValued":false,
"indexed":true,
"required":true,
"stored":true},
{
"name":"l",
"type":"pint",
"indexed":true,
"stored":true},
{
"name":"t",
"type":"pdate",
"indexed":true,
"stored":true},
{
"name":"trans",
"type":"string",
"indexed":true,
"stored":true}]}
In our case, the ID has the type uuid. If I change it I get an error:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"replace-field":{
"name":"id",
"type":"uuid",
"stored":true,
"indexed":true}
}' http://localhost:8983/solr/trans/schema/fields
{
"responseHeader":{
"status":500,
"QTime":48},
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"Can't load schema managed-schema: _root_ field must be defined using the exact same fieldType as the uniqueKey field (id) uses: uuid",
...
It does not help to change both the _root_ and id either:
curl -X POST -H 'Content-type:application/json' --data-binary '{
"replace-field":{
"name":"id",
"type":"uuid",
"stored":true,
},
"replace-field":{
"name":"_root_",
"type":"uuid",
"stored":true,
"docValues":false,
"indexed":true,
"stored":false}
}
' http://localhost:8983/solr/trans/schema
{
"responseHeader":{
"status":500,
"QTime":50},
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"Can't load schema managed-schema: _root_ field must be defined using the exact same fieldType as the uniqueKey field (id) uses: uuid",
How do I change the type of the id in solr properly?

Related

Appsync mutatation query giving MalformedHttpRequestException via POST

I am trying out the default example for realtime updates on AWS appsync.
Schema
type Channel {
name: String!
data: AWSJSON!
}
type Mutation {
publish(name: String!, data: AWSJSON!): Channel
}
type Query {
getChannel: Channel
}
type Subscription {
subscribe(name: String!): Channel
#aws_subscribe(mutations: ["publish"])
}
Running this query through AWS query page gives success
mutation PublishData {
publish(data: "{\"msg\": \"hello world!\"}", name: "channel") {
data
name
}
}
When trying to execute the same through HTTP Post, it gives error.
curl --location --request POST 'https://XXXX.ap-south-1.amazonaws.com:443/graphql' \
--header 'x-api-key: XXXXX' \
--header 'Content-Type: application/graphql' \
--data-raw '{
"query": "mutation PublishData { publish(data: \"{\"msg\": \"hello world!\"}\", name: \"broadcast\") { data name } }",
"variables": "{}"
}'
Executing this query gives success
curl --location --request POST 'https://XXX.ap-south-1.amazonaws.com:443/graphql' \
--header 'x-api-key: XXXX' \
--header 'Content-Type: application/graphql' \
--data-raw '{
"query": "mutation PublishData { publish(data: \"{}\", name: \"broadcast\") { data name } }",
"variables": "{}"
}'
I am unable to figure out where is the syntax error.
I got it working using variables. This is the syntax.
{
"query": "mutation($data:AWSJSON!) { publish(data: $data, name: \"broadcast\") { data name } }",
"variables": {"data":"{\"abs\":1}"}
}

Elasticsearch 7.7 how to read several documents, not fetch all the documents

I am using ElasticSearch 7.7 in CentOS 8 box. I could creat index, type by REST format by command curl. For example, I could use
curl -X PUT "localhost:9200/testindex2"
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/testindex2/man/1/" -d '{ "name" : "shiny2", "age": 28}'
curl -XGET "localhost:9200/testindex2/man/1/"
curl -XGET "localhost:9200/testindex2/man/_search?pretty"
But if I have inserted many documents, how could I do query by REST command line using command curl to find particular age = 28's documents?
curl -XGET "localhost:9200/testindex2/_search?pretty&q=age:28"
that is the simplest way to query.
more option and documentation:
https://www.elastic.co/guide/en/elasticsearch/reference/7.8/search-search.html
also you can use Match or Term query with JSON body format.
curl -XGET 'localhost:9200/testindex2/_search?pretty' -d '
{
"query": {
"term": {
"age": {
"value": "28"
}
}
}
}'
more documentation:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html

How to update couchbase lite view with Rest API?

How to update couchbase lite view with Rest API ?
From Rest API how to tell indexer that view is updated . I have tried the below code but it did not work.It still returns the old index.
What is the correct way of telling indexer that view is updated so that it can recreate the index.
'PUT'
{db}/_design/todo
{
"_rev":"hf675757577hhfh",
"views":{
"list":{
"map":function(doc){
if(doc.type=='list')
{
emit(doc._id,{"name":doc.name});
}
},
//"version":"1.0" (I have tryied this but not work)
}
}
}
//My view create request was like below:
{db}/_design/todo
{
"views":{
"list":{
"map":function(doc){
if(doc.type=='list')
{
emit(doc._id,{"name":doc.name});
}
},
//"version":"1.0" (I have tryied this but not work)
}
}
}
It looks like you may just have some formatting problems. This shows how to do what you're trying from the command line:
curl -X PUT 'http://localhost:4985/db/_design/todo' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "_rev": "hf675757577hhfh", "views": { "list": { "map": "function(doc) { if (doc.type == \"list\") { emit(doc._id, { \"name\": doc.name }); }}"}}}'
You can test your results with this command:
curl -X GET 'http://localhost:4985/db/_design/todo/_view/list'
You may want to refer to the documentation, which has more examples, at https://developer.couchbase.com/documentation/mobile/current/guides/sync-gateway/views/index.html

how insert data to Elasticsearch without id

I insert data to Elasticsearch with id 123
localhost:9200/index/type/123
but I do not know what will next id inserted
how insert data to Elasticsearch without id in localhost:9200/index/type?
The index operation can be executed without specifying the id. In such a case, an id will be generated automatically. In addition, the op_type will automatically be set to create. Here is an example (note the POST used instead of PUT):
$ curl -XPOST 'http://localhost:9200/twitter/tweet/' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
In my case, using nodejs and the elasticsearch package I did it this way using the client:
client.index ()
var elasticsearch = require ('elasticsearch');
let client = new elasticsearch.Client ({
host: '127.0.0.1: 9200'
});
client.index ({
index: 'myindex'
type: 'mytype',
body: {
properti1: 'val 1',
properti2: ['y', 'z'],
properti3: true,
}
}, function (error, response) {
if (error) {
console.log("error: ", error);
} else {
console.log("response: ", response);
}
});
if an id is not specified, elasticsearch will generate one automatically
In my case, I was trying to add a document directly to an index, e.g. localhost:9200/messages, as opposed to localhost:9200/someIndex/messages.
I had to append /_doc to the URL for my POST to succeed: localhost:9200/messages/_doc. Otherwise, I was getting an HTTP 405:
{"error":"Incorrect HTTP method for uri [/messages] and method [POST], allowed: [GET, PUT, HEAD, DELETE]","status":405}
Here's my full cURL request:
$ curl -X POST "localhost:9200/messages/_doc" -H 'Content-Type:
application/json' -d'
{
"user": "Jimmy Doe",
"text": "Actually, my only brother!",
"timestamp": "something"
}
'
{"_index":"messages","_type":"_doc","_id":"AIRF8GYBjAnm5hquWm61","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":3}
You can use POST request to create a new document or data object without specifying id property in the path.
curl -XPOST 'http://localhost:9200/stackoverflow/question' -d '
{
title: "How to insert data to elasticsearch without id in the path?"
}
If our data doesn’t have a natural ID, we can let Elasticsearch autogenerate one for us. The structure of the request changes: instead of using the PUT verb ("store this document at this URL"), we use the POST verb ("store this document under this URL").
The URL now contains just the _index and the _type:
curl -X POST "localhost:9200/website/blog/" -H 'Content-Type: application/json' -d'
{
"title": "My second blog entry",
"text": "Still trying this out...",
"date": "2014/01/01"
}
'
The response is similar to what we saw before, except that the _id field has been generated for us:
{
"_index": "website",
"_type": "blog",
"_id": "AVFgSgVHUP18jI2wRx0w",
"_version": 1,
"created": true
}
Autogenerated IDs are 20 character long, URL-safe, Base64-encoded GUID strings. These GUIDs are generated from a modified FlakeID scheme which allows multiple nodes to be generating unique IDs in parallel with essentially zero chance of collision.
https://www.elastic.co/guide/en/elasticsearch/guide/current/index-doc.html
It's possible to leave the ID field blank and elasticsearch will assign it one. For example a _bulk insert will look like
{"create":{"_index":"products","_type":"product"}}\n
{JSON document 1}\n
{"create":{"_index":"products","_type":"product"}}\n
{JSON document 2}\n
{"create":{"_index":"products","_type":"product"}}\n
{JSON document 3}\n
...and so on
The IDs will look something like 'AUvGyJMOOA8IPUB04vbF'

How to update a document using the Elasticsearch Update API?

I have indexed a document in Elasticsearch as follows:
{
_parent: chow-demo
_index: prototype_2013.01.02
_type: chow-clfg
_id: Nx4JcvyxTPujkyy0Jq5BNw
_score: 11.600378
_source: {
chow-clfg: {
#type: chow-clfg
clfg: Cg5iV00z4woYAAAARQ0
#timestamp: 2013-01-02T06:26:00.000Z
count: 1
}
}
}
I tried to update the count field by the following command:
curl -XPOST 'localhost:9200/prototype_2013.01.02/chow-clfg/Nx4JcvyxTPujkyy0Jq5BNw/_update' -d '{"script":"ctx._source.chow-clfg.count+=num","params":{"num":1}}'
However I received the following error instead:
{"error":"RemoteTransportException[[Vesta][inet[/10.15.78.249:9300]][update]]; nested: DocumentMissingException[[prototype_2013.01.02][0] [chow-clfg][Nx4JcvyxTPujkyy0Jq5BNw]: document missing]; ","status":404}
What exactly have I done that is missing? I was following the documents at http://www.elasticsearch.org/guide/reference/api/update.html and yet it doesn't work.
Also, I included the parent field:
curl -XPOST 'localhost:9200/prototype_2013.01.02/chow-clfg/Nx4JcvyxTPujkyy0Jq5BNw/_update' -d '{"parent":"chow-demo","script":"ctx._source.chow-clfg.count+=num","params":{"num":1}}'
And it still didn't work. Anyone can help me with this error?
Basically it was incorrect syntax that caused the problem of not being able to update.
Error:
curl -XPOST 'localhost:9200/prototype_2013.01.02/chow-clfg/Nx4JcvyxTPujkyy0Jq5BNw/_update' \
-d '{"script":"ctx._source.chow-clfg.count+=num","params":{"num":1}}'
Correct syntax:
curl -XPOST 'localhost:9200/prototype_2013.01.02/chow-clfg/Nx4JcvyxTPujkyy0Jq5BNw/_update?parent=chow-demo'
-d '{"script":"ctx._source[\"chow-demo\"].count+=num","params":{"num":1}}'
The parent mapping should be included, together with the type name in its proper syntax:
ctx._source[\"chow-demo\"].count+=num

Resources