elastic for elasticsearch v6

Hi,

after an update of Elastic to version 6, I’m not able to use the Search function in combination with the body argument.

Search(“Index”, q=‘status:“B”’)
gives a lot of results, while

res ← Search(“Index”, q=‘status:“B”’,
body = '{ “_source”: [“_id”, “quantity”, “cost”] })

gives;
Error: 406 - Content-Type header is not supported

It looks like its normal behaviour:

But I can’t figure out how to adjust the query to run and give back only 3 fields instead of all fields.

Anyone?

Ace

I can’t replicate the problem

Can you edit or update with runnable code? e.g., the body argument is not valid '{ “_source”: ["_id", “quantity”, “cost”] }

Can you also run with curl verbose, like Search(..., config = httr::verbose()) and paste in the headers (REMOVING ANY SECURE INFORMATION) or at least look at them yourself to see if there’s anything wrong there.

Hi sckott,

I guess following code should be runnable after adjustment of the index:
Search(“index”, body = ‘{ “_source”: [“_id”]}’, config= httr::verbose())

Return from the verbose:

→ POST /index/_search?version=false HTTP/1.1

→ Host: 127.0.0.1:9200

→ User-Agent: libcurl/7.56.1 r-curl/3.1 httr/1.3.1

→ Accept-Encoding: gzip, deflate

→ Accept: application/json, text/xml, application/xml, /

→ Content-Length: 21

{ “_source”: [“_id”]}

← HTTP/1.1 406 Not Acceptable

← content-type: application/json; charset=UTF-8

← content-encoding: gzip

← content-length: 90

Error: 406 - Content-Type header is not supported

I guess I should make an explicit statement for the content type, but no idea how to do this.

Ace

Hi,

after your suggestion and searching on the internet, I found the next workaround:
Search(“index”, body = ‘{ “_source”: ["_id"]}’, config= httr::add_headers(“Content-Type” = “application/json”))
Marybe there are easier ways, but at least it worked :blush:

Ace

So passing in httr::add_headers(“Content-Type” = “application/json”) worked?

I’ll keep looking at the code to see what might be causing that problem with the content type - seems it’s not being passed for some reason, seems to be dependent on your particular configuration so far.

Can you paste in your sessionInfo()

Hi,

the addition of httr::add_headers(“content-Type”=“application/json”) worked indeed.

sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2012 R2 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=Dutch_Belgium.1252 LC_CTYPE=Dutch_Belgium.1252
[3] LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Belgium.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] data.table_1.10.4 elastic_0.7.8

loaded via a namespace (and not attached):
[1] httr_1.3.1 compiler_3.4.1 R6_2.2.2 curl_3.1 jsonlite_1.5

Ace

Do you still have the problem with the newest version of elastic v0.8, up on CRAN since Sep last year https://cran.rstudio.com/web/packages/elastic/ ?

Scott,

before I posted this thread, I made sure I ran update.packages(“elastic”), so I was on the newest version (I thought).
When I do this I have version 0.7.8
Now I downloaded the suggested 0.8 version, installed it from a local zip file and now it all works without the addition of httr::add_header(…)

Thanks!

1 Like

Great, glad it works!