Schema Defination


(Siv) #1

Hi

Im trying to crate schema for below data structure

{
"student" : {
"name" : "John",
"subject" : [1957, 1952]
}
}

In this, subject has to take array of values, I have defined my schema as

{
"student" : {
"properties" : {
"name" : {"type" : "string"},
"lists" : {
"properties" : {
"subject" : {"type" : "string"}
}
}
}
}
}

Is it a right structure ?


(Vincent Tran) #2

Looks almost like you're looking for the mapping of this "schema". How about:

{
  "mappings": {
    "type1": {
      "properties": {
        "student": {
          "type": "nested"
          "properties": {
            "name" :{
                "type": "string"
            }
            "subject": {
                "type" : "array"
            }
          }
        }
      }
    }
  }
}

The field student can be either nested or object. Read more about nested object here to see if it fits your use case.

https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html


(Magnus B├Ąck) #3

What does lists come from? Also, the elements of the subject array are integers, not strings. This should be better:

{
  "student" : {
    "properties" : {
      "name" : {"type" : "string"},	
      "subject" : {"type" : "integer"}
    }
  }
}

(system) #4