Create index questions


(Liuuu) #1
PUT test
{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "_doc" : {
            "properties" : {
                "field1" : { "type" : "text" }
            }
        }
    }
}

what does _doc means when creating a index?
Can I specific a typename instead of _doc, as student replacing _doc

PUT test
{
    "settings" : {
        "number_of_shards" : 1
    },
    "mappings" : {
        "students" : {
            "properties" : {
                "field1" : { "type" : "text" }
            }
        }
    }
}

(Mark Walkom) #2

That is the _type. This is deprecated and will be removed in 7.0, so we would suggest not using anything but that default value.

You should add this as a new field instead.


(Liuuu) #3

/index/${typename}/

I wanna create a mapping for this type
/test/students as for students
how does it become a field name other than a typename


(Mark Walkom) #4

Don't do that.

Put "typename": "student" in your document.


(Liuuu) #5

Sorry, I am quite new to elastic.
the purpose is to create a index name test and initialize the mapping of a typename = "students"

PUT test
{
  "settings": {
        "number_of_replicas": 1,
        "number_of_shards": 1
  },
  "mappings" : {
    "_doc" : {
        "properties" : {
            "field1" : { "type" : "text" }
        }
    }
 }
}

above that's referring to the docs,
I am quite confusing here(what is _doc means here)
So I am intent to replace _doc to students, because students is my table name(in elastic world typename)

probably I misused the word typename
below is what I want as a result for each document
_index: "test", _type: "students"

As your said:

Put "typename": "student" in your document.

I don't really know

  1. where should I put my "typename": "student" to.
  2. And how to achieve my purpose initialize a index with a typename(table name) as well as set the mapping of the typename's fields

Many thanks.


(Mark Walkom) #6

Do this;

PUT test
{
  "settings": {
        "number_of_replicas": 1,
        "number_of_shards": 1
  },
  "mappings" : {
    "_doc" : {
        "properties" : {
            "field1" : { "type" : "text" },
            "typename" : { "type" : "text" }
        }
    }
 }
}

Ignore _doc, ignore _type, they are deprecated features and using them will only cause more problems.


(Liuuu) #7

Sorry, I thought you still misunderstand.
I wanna the type be the table name . like this test/students/1

And, specify the filed such as name, gender, id, age of students not on index,
_index: "test", _type: "students"

So, I am intent to do

PUT test
 "mappings" : {
    "students" : {
        "properties" : {
            "field1" : { "type" : "text" }
        }
    }
 }

in your last reply

PUT test
{
  "settings": {
        "number_of_replicas": 1,
        "number_of_shards": 1
  },
  "mappings" : {
    "_doc" : {
        "properties" : {
            "field1" : { "type" : "text" },
            "typename" : { "type" : "text" }
        }
    }
 }
}

I thought you still used the _doc.
Is there something I misunderstand about mappings?


(Mark Walkom) #8

Please read https://www.elastic.co/blog/removal-of-mapping-types-elasticsearch.

As I have been saying - Do Not Use Types. They will be removed very soon.
If you use this type then you will need to make more changes in the very near future.