How to dynamically recognize points via HTTPS ingestion? - elasticsearch

We are sending https requests to ingest data. How can the request be formatted so that Elastic dynamically maps the 'geo_point' field as type:point and not text or number? Thank you!
curl -X POST "https://in-https.URL" -H 'Content-Type: application/json' -d'
{
    "geo_point": -71.34, 41.12
}
'

geo_point dynamic mapping is not supported - https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-field-mapping.html.
To index a geo_point field, precede you original request with a request to _mapping to add your geo_point field to the index mapping - https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html

Related

How to send json data elastic search get request url

Following works fine
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query" : {
"query_string" : {
"query" : "chicag*",
"fields" : ["name"],
"_name":"myqry"
}
}
}
'
How can I create a browser url for this GET request ? I URLEncoded the json and tried -
localhost:9200/_search?data=%7B%0A%20%20%22query%22%20%3A%20%7B%0A%20%20%20%20%22query_string%22%20%3A%20%7B%0A%20%20%20%20%20%20%22query%22%20%3A%20%22chicag%2A%22%2C%0A%20%20%20%20%20%20%22fields%22%20%20%3A%20%5B%22name%22%5D%2C%0A%20%20%20%20%20%20%22_name%22%3A%22Chcagoooo%22%0A%20%20%20%20%7D%0A%20%20%7D
but it did not work
It is definitely possible to send your DSL query as a query string parameter using the source parameter like this:
localhost:9200/_search?pretty&source={"query":{"query_string":{"query":"chicag*","fields":["name"],"_name":"myqry"}}}&source_content_type=application/json
I am using multi-get API _mget. In my case, I am using the following URL to get all the documents in the specified range.
Refer: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/docs-multi-get.html#mget-ids
This example displays documents with id 49 and 50.
http://localhost:9200/my_index/_mget?pretty&source={ "ids" : [49, 50] }&source_content_type=application/json

Post JSON data to elastic search using curl command

I am trying to post Json file to elastic search and facing below errors
curl -XPOST http://localhost/test-index/doc -H "Content-Type: application/json" -d #test.json
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [test-index] as the final mapping would have more than 1 type: [_doc, doc]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [test-index] as the final mapping would have more than 1 type: [_doc, doc]"},"status":400}
test.json content
{
"name":"John Smith",
"age":"38"
}
am I missing anything
To post Json data to elasticsearch using curl command, you can try out this command:
curl -XPOST http://localhost:9200/test-index/_doc -H "Content-Type: application/json" -d #test.json
The command with which, you are trying to post Json file, works fine with Postman.
The error returned is
"reason":"Rejecting mapping update to [test-index] as the final
mapping would have more than 1 type: [_doc, doc]"}]
it mean that your index already have a type _doc and you try to create a new type doc. As version ~7.?? of elastic support only one type you can't create your data.
You need to add "_" before doc in your request.
http://localhost/test-index/doc <-- not correct
http://localhost/test-index/_doc <-- correct

Search query to match all and return all data without using curl

I am working with postman and i want to try using getting all data from my index, now when using curl
curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}
but i want to write a search and return all data, my index name is tourdata and type is tours
127.0.0.1:9200/tourdata/tours/_search
how do i continue
So i found that i need to add size to my query parameter, This worked for me.
127.0.0.1:9200/tourdata/tours/_search?size=7000&pretty=true

I am getting this error in elasticsearch

{
"error":"Content-Type header [application/x-www-form-urlencoded] is not supported",
"status":406
}
Though I used header Content-Type
Here is the the command I used for indexing a customer document for a customer index:
curl -XPUT localhost:9200/customer/doc/1 -H 'Content-Type:application/json' -d '{"name":"abcd"}'

Cannot turn Elasticsearch dynamic mapping on

I disabled dynamic mapping with
curl -XPUT 'localhost:9200/_template/template_all?pretty' -H 'Content-Type: application/json' -d' { "template": "*", "order":0, "settings": { "index.mapper.dynamic": false }}'
I wanted to turn it back on with
curl -XPUT 'localhost:9200/_template/template_all?pretty' -H 'Content-Type: application/json' -d' { "template": "*", "order":0, "settings": { "index.mapper.dynamic": true }}'
It has confirmed it as true, but when I try to have logstash send information to it, in logstash error logs I get back-
"reason"=>"trying to auto create mapping, but dynamic mapping is disabled"
How do I actually turn dynamic mapping back on?
Looks like index for logstash was created with old template (before you update template). Because when you update you template only new indexes will have updated mapping and settings.
Check is index exists:
curl -XGET 'localhost:9200/LOGSTASH_INDEX_NAME_HERE'
If index exists and you can delete this index - do it. After this when logstash will try to send something - index will be created with the new mapping.

Resources