Differences in PUT requests in ES versions

Hello everyone :hatched_chick:
I actively study Elasticsearch.
I had to update my version ES to the latest from 5. But here I ran into a problem, the answer to which I could not find in the documentation.

I used ES 5 version, when adding new information for example to this sections:

PUT /coin_charts/btc/1
PUT /coin_charts/eth/1
PUT /coin_charts/ada/1

It automatically created the structure and information was added.

But in the new version, when trying to do the same, it gives an error:

    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Invalid type: expecting [btc] but got [eth]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Invalid type: expecting [btc] but got [eth]"
    },
    "status": 400

How can this be corrected? Please tell a newbie :slight_smile:

Please see Removal of mapping types | Elasticsearch Guide [7.16] | Elastic

I'm not sure about information actuality here, but I use the first example and get an error :worried:
This request from tutorial:

Response:

Yes that's why it says "Originally, the workflow would have looked something like this" and then shows you how to do it now :slight_smile: That's what you need to adapt to.

1 Like

Sorry, my english level let me down :sweat_smile:

But, i can't make this mappings already the second day...
I can’t make the structure I need in any way, maybe I don’t understand something.
I need to make stuctures like this:

/coin_charts/bitcoin/1
/coin_charts/bitcoin/2
/coin_charts/bitcoin/3
/coin_charts/ethereum/1
/coin_charts/ethereum/2
/coin_charts/ethereum/3

However, in each section(bitcoin, ethereum and 12 thousand others) structure should be the same:

{
      "priceUsd": 100,
      "time": 1643139643011
}

Could you help with creting mapping? I beg you, I can't deal with this :frowning:
I will be very grateful for your help

Elasticsearch no longer supports specifying multiple document types for an index so I would recommend adding a field to each document that contains the type and use a default type (_doc) as follows:

coin_charts/_doc/bitcoin-1
{
      "currency": "bitcoin",
      "priceUsd": 100,
      "time": 1643139643011
}

You can let Elasticsearch assign document IDs or set them manually yourself.

1 Like

But the problem is that in the future I will need to search by currency name and time, if only one value is indexed, is it possible to search by two parameters at the same time?

I do not understand the problem. You can search on multiple fields and combine criteria using boolean queries.

I do not understand what you mean.

You need to introduce a new field in your document body to differentiate the currency name. So 2 fields will be indexed.
"currency name" & "time".
You search the documents using 2 fields. (currency+time)

It basically moves the old "_type" value into the document body and you need to add the currency-name to your query string.

Elasticsearch by default will index all the fields in your document body, unless you tell it not to from "mapping". With the above example after the migration, you should have 3 fields getting indexed. "currency name", "time", "price". Unless you changed this behavior from "mapping". Hope it helps.

1 Like

Thank you very much. Now I understand how it works and why it works :hugs:

Thanks for the extra clarification. This helped me too :hugs:
Now i use this request:

{
  "query": {
    "bool" : {
        "must": [{
          "term": {
            "currency" : "bitcoin"
          }
        },
        {
          "range": {
            "time": {
                "gt": 1642715000000
            }
          }
        }
      ]
        "size": 1
}

I hope so right. Although the answer shows the right one, but still, maybe somehow I can improve my query :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.