-
Notifications
You must be signed in to change notification settings - Fork 965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I set header in the search endpoint 'Content-Type'=> 'application/json' #205
Comments
It should be possible via setting custom curl options. Are you using ES-PHP 1.0 or 2.0? The syntax will be a little different for each. |
I am using v1.3.3 Can you tell how to set header 'Content-Type'=> 'application/json' under this version |
Untested, but I think this should work: $params = [
'guzzleOptions' => [
'curl.options' => [
CURLOPT_HTTPHEADER => [ 'Content-Type: application/json' ]
]
];
$client = new Elasticsearch\Client($params); If it doesn't, I'll break out the debugger and test it to find the right invocation. But I think that should work :) You don't have to use |
Yeah! It worked for me! Thanks a lot! |
Great! Happy to help :) |
Hey! I have one more question. How to query in elasticsearch php for nested fields. For eg. If I want to search for "_source"
"field1": "val1",
"field2": {
"field21": {
"field22" : "data"
}
} |
You can use the full dot notation path to the field: $params = [
'query' => [
'match' => [
'field2.field21.field22' => 'data'
]
];
] |
Thanks! got it! |
Great! Closing for now, feel free to reopen if you have more problems (or open a new ticket). |
@polyfractal how would one set custom headers in 2.x? |
@adilhashem You can set curl headers with the $client = Elasticsearch\ClientBuilder::create()->build();
$params = [
'index' => 'test',
'type' => 'test',
'body' => [
'query' => [
'match_all' => []
]
],
'client' => [
'curl' => [
CURLOPT_HTTPHEADER => [
'Content-type: application/json',
'Authorization: foobarbaz'
]
]
]
];
$client->search($params); It's done on a per-request basis right now, there isn't (currently) a way to specify it for the entire client. There's an open issue for that: #382 |
@polyfractal thanks! |
Recent ES 6.0 comes with strict content-type checking, so now you have define the content type, is not optional anymore, thanks @polyfractal , I felt lost for a couple of days. https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests |
@donluismx FYI, if you're using Elasticsearch 6.0+, you need to upgrade your ES-PHP client to the 6.0 branch too. ES-PHP 6.0+ sets the content-type headers automatically: fd3b0f1 |
In #721 #721 $headers = [];
//add below line at line number 114 in this file///// |
I try to use this code but for some reason, it doesn't work for I get. "Notice: Array to string conversion" error and the request is not being sent. |
No description provided.
The text was updated successfully, but these errors were encountered: