elastic / elasticsearch-definitive-guide

The Definitive Guide to Elasticsearch
https://www.elastic.co/guide/en/elasticsearch/guide/current/index.html
Other
3.55k stars 2.83k forks source link

Invalid Sense example code #128

Open w33ble opened 10 years ago

w33ble commented 10 years ago

I first noticed this in /080_Structured_Search/05_term.asciidoc - The following example is in the docs, but it doesn't work when you try to copy and paste it into Sense, and the link to view in Sense actually sends different content.

Docs (results in an error, text is not passed to the request)

GET /my_store/_analyze?field=productID
XHDK-A-1293-#fJ3

note: the request is not escaped (# vs %23), so even if you fix the syntax, you get different results (the content from # on is dropped) - perhaps this should also be pointed out in the docs.

Sense

GET /my_store/_analyze?field=productID&text=XHDK-A-1293-%23fJ3

This is also an issue with the code in /052_Mapping_Analysis/40_Analysis.asciidoc and I suspect in other parts of the docs as well.

It's possible this is actually a Sense bug, but someone took the time to update the Sense json in the docs without updating the examples, and the docs are technically broken as-is.

clintongormley commented 10 years ago

Hi @w33ble

Yes... This is a tricky one. Elasticsearch can accept plain text in the body, eg:

curl localhost:9200/_analyze?analyzer=standard -d '
Text to analyze here
'

This is a much clearer syntax for explanation purposes than:

curl localhost:9200/_analyze?analyzer=standard&text=Text%20to%20analyze%20here

However, Sense can only handle JSON bodies, not plain text. With a JSON body it knows where the end of the body should be. A plain text body might include paragraphs, so where does the body actually end?

There is an open issue (https://github.com/elasticsearch/elasticsearch/issues/5866) to allow the analyze end point to accept JSON instead of text, which would solve this issue.

w33ble commented 10 years ago

Cool, thanks for the feedback. Curious: is analyze the only command that's takes text instead of JSON?

clintongormley commented 10 years ago

No, there are the scroll and clear scroll APIs too, but those are less problematic.

sxbo672158 commented 9 years ago

Just curious how do I do scroll api in Sense then? Thanks,