how to load a JSON file to solr using `pysolr`? - solr

The following python code adds a document but without the json contents:
solr_instance = pysolr.Solr('http://192.168.45.153:8983/solr/test', timeout=60)
json_filename = '/path/to/file/test.json'
argws = {
'commit': 'true',
'extractOnly': False,
'Content-Type': 'application/json',
}
with open(json_filename, 'rb') as f:
solr_instance.extract(f, **argws)
solr_instance.commit()
using curl from the command line works as expected:
$ curl 'http://192.168.45.153:8983/solr/test/update?commit=true' \
--data-binary #/path/to/file/test.json \
-H 'Content-Type: application/json'
the file has following content:
$ cat /cygdrive/w/mist/test.json
--> [{"x": "a","y": "b"}]
I'm using pysolr 3.6.0 and solr 6.5.0

The extract() method refers to a request made against the ExtractingRequestHandler, which is meant to be used for extracting content from rich documents (such as PDFs, etc.).
You can use the regular .add method to submit the decoded JSON to Solr:
import json
solr.add(json.load(json_filename))
.. should work.

Related

How to use iteration data with newman

I have a collection in Postman which loads "payload objects" from a json file and want to make it run in newman from command like.
POST request
Body: of POST request I have got {{jsonBody}}
Pre-request Script: logically pm.globals.set("jsonBody", JSON.stringify(pm.iterationData.toObject()));
and a file.json file with this kind of "objects":
[
{
"data": {
"propert1": 24,
"property2": "24__DDL_VXS",
...
},
{
"data": {
"propert1": 28,
"property2": "28__HDL_VDS",
...
}
...
]
Works like a charm in Postman.
Here is what I'm trying to run in cmd.
newman run \
-d file.json \
--global-var access_token=$TOK4EN \
--folder '/vlanspost' \
postman/postman_collection_v2.json
Based on the results I am getting - it looks like that newman is not resolving flag:
-d, --iteration-data <path> Specify a data file to use for iterations (either JSON or CSV)
and simply passes as payload literally this string from Body section: {{jsonBody}}
Anyone has got the same issue ?
Thx
I did that way and it worked.
Put collection and data file into a same directory. For example:
C:\USERS\DUNGUYEN\DESKTOP\SO
---- file.json
\___ SO.postman_collection.json
From this folder, make newman command.
newman run .\SO.postman_collection.json -d .\file.json --folder 'vlanspost'
This is the result:

Not able to upload excel file using karate [duplicate]

I have a postdata presigned URL of Amazon S3. I want to use it in a Karate feature file to upload a file (say: pdf)
Here is a sample Curl request that I need to perform Using Karate POST request
curl --location --request POST '<s3bucketURL>' \
--form 'key=some_key_fileName' \
--form 'x-amz-meta-payload={JsonObject}' \
--form 'Content-Type=application/pdf' \
--form 'bucket=<BucketName>' \
--form 'X-Amz-Algorithm=AWS4-HMAC-SHA256' \
--form 'X-Amz-Credential=<AWS_Credential>' \
--form 'X-Amz-Date=<Date>' \
--form 'Policy=<Policy_Hash>' \
--form 'X-Amz-Signature=<Signature_Hash>' \
--form 'file=#/Users/sahildua/validfile.pdf'
I got a response (having the preSignedUrl) from a server and used using below code in a feature-file
"url": "<s3bucketURL>",
"fields": {
"key": "some_key_fileName",
"x-amz-meta-payload": "{JsonObject}",
"Content-Type": "application/pdf",
"bucket": "<BucketName>",
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Credential": "<AWS_Credential>",
"X-Amz-Date": "<Date>",
"Policy": "<Policy_Hash>",
"X-Amz-Signature": "<Signature_Hash>"
I tried
Given url response.url
* def fieldData = response.fields
* print fieldData
* form fields fieldData
And multipart file file = { read: '../testData/validPdfFile.pdf'}
When method post
Then match responseStatus == 204
But I get a validation XML error from Amazon S3 for incorrect field values
<Error>
<Code>InvalidArgument</Code>
<Message>Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.</Message>
<ArgumentName>key</ArgumentName>
<ArgumentValue></ArgumentValue>
<RequestId><id></RequestId>
<HostId><someid></HostId>
</Error>
I expect 204 No Content and the file to be uploaded the S3 bucket
Try this change:
And multipart file file = { read: '../testData/validPdfFile.pdf'}
Read this for a little more explanation: https://github.com/intuit/karate/tree/develop#multipart-file
Other than that you seem to be doing everything right. So it is up to your de-bugging skills now. Or give us a way to replicate: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Inserting a ContentVersion using Angularjs $http

I have been trying to insert files using Salesforce Chatter REST API but its been documented for curl. I am unable to find how to do the same in Angularjs using $http with visualforce. I am not able to set the request header and body properly. Please provide the header and body contents for the request, if this has to be done using javascript rather than curl.
Example for creating a new Document
curl https://yourInstance.salesforce.com/services/data/v23.0/sobjects/Document/
-H "Authorization: Bearer token"
-H "Content-Type: multipart/form-data;boundary=\"boundary_string\""
--data-binary #newdocument.json
Example request body for creating a new Document
This code is the contents of newdocument.json. The binary data for the PDF content has been omitted for brevity and replaced
with “Binary data goes here.” An actual request contains the full binary content.
--boundary_string
Content-Disposition: form-data; name="entity_document";
Content-Type: application/json
{
"Description" : "Marketing brochure for Q1 2011",
"Keywords" : "marketing,sales,update",
"FolderId" : "005D0000001GiU7",
"Name" : "Marketing Brochure Q1",
"Type" : "pdf"
}
--boundary_string
Content-Type: application/pdf
Content-Disposition: form-data; name="Body"; filename="2011Q1MktgBrochure.pdf"
Binary data goes here.
--boundary_string--

org.apache.solr.common.SolrException Stream Body is disabled

I have setup apache solr 7.1 and using postman tool to query it. But when I am trying to delete indexed data using postman I get following error.
Request:
GET http://localhost:8983/solr/solr-sample3/update?stream.body={
"delete": {
"query": "*:*"
},
"commit": { }
}
Body:
{
"error": {
"metadata": [
"error-class",
"org.apache.solr.common.SolrException",
"root-error-class",
"org.apache.solr.common.SolrException"
],
"msg": "Stream Body is disabled. See http://lucene.apache.org/solr/guide/requestdispatcher-in-solrconfig.html for help",
"code": 400
}
}
It was working in previous solr version solr 6.6. I went through the lucene documentation but I am not able to figure it out.
You don't need to enable the stream body. Just use a curl POST request specifying the data type as text/xml
curl http://localhost:8983/solr/solr-sample3/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
Or if you're using the Post Tool included in solr:
bin/post -c core_name -type text/xml -out yes -d $'<delete><query>*:*</query></delete>'
I went though the documentation, it says i need to enable stream body as it has been disabled in solr 7.1 .
to enable use :
curl http://localhost:8983/solr/solr-sample3/config -H 'Content-type:application/json' -d'{
"set-property" : {"requestDispatcher.requestParsers.enableRemoteStreaming":true},
"set-property" : {"requestDispatcher.requestParsers.enableStreamBody":true}
}'
Here is what worked for me, using cURL and avoiding to enable stream body:
curl http://localhost:8983/solr/solr-sample3/update?commit=true -X POST -H "Content-Type: text/xml" --data-binary "<delete><query>*:*</query></delete>"

Restangular GET request with data

Is there a way to send a GET request with data using Restangular? I'm using Parse as a backend for my AngularJS app and to login it requires a GET with data:
curl -X GET \
-H "X-Parse-Application-Id: ..." \
-H "X-Parse-REST-API-Key: ..." \
-G \
--data-urlencode 'username=cooldude6' \
--data-urlencode 'password=p_n7!-e8' \
https://api.parse.com/1/login
From: https://parse.com/docs/rest#users-login
I've tried a customOperation but it doesn't send the data
var login = Restangular.all('login');
login.customOperation('get', '', {}, {}, {username: 'user'}); // ignore encoding for now
This just sends a GET request to /login but without any data.
I misunderstood the Parse.com documentation. I thought the credentials had to be send as body of the request because of the -G in the curl command. But apparently they need to be send as normal parameters.

Resources