Euri
Euri

Reputation: 31

Creating index with nested type document

I tried the following code to create an index with the following mapping. I am trying to create an index with type "nested". This code does not show any error but does not seem to work. Your help is much appreciated.

def setting():
return {  "stringIndex_mapping" : {
            "mappings" :
                    {
                      "stringindex" : {
                        "mappings" : {
                          "files" : {
                            "properties" : {
                              "BaseOfCode" : {
                                "type" : "long"
                              },
                              "BaseOfData" : {
                                "type" : "long"
                              },
                              "Characteristics" : {
                                "type" : "long"
                              },
                              "FileType" : {
                                "type" : "long"
                              },
                              "Id" : {
                                "type" : "string"
                              },
                              "Strings" : {
                                "type" : "nested",
                                "properties" : {
                                  "FileOffset" : {
                                    "type" : "long"
                                  },
                                  "RO_BaseOfCode" : {
                                    "type" : "long"
                                  },
                                  "SectionName" : {
                                    "type" : "string"
                                  },
                                  "SectionOffset" : {
                                    "type" : "long"
                                  },
                                  "String" : {
                                    "type" : "string"
                                  }
                                }
                              },
                              "SubSystem" : {
                                "type" : "long"
                              }
                            }
                          }
                        }
                      }
                    }
            }

}

def createIndex():
    es = elasticsearch.Elasticsearch()
    settings = setting()

    es.indices.create(
                index = "stringindex",
                body = settings
            )

Upvotes: 0

Views: 435

Answers (1)

progrrammer
progrrammer

Reputation: 4489

You have problem with json structure of your mapping.

here is what I've changed to,

return this mapping from your setting() method

{
   "mappings": {
      "files": {
         "properties": {
            "BaseOfCode": {
               "type": "long"
            },
            "BaseOfData": {
               "type": "long"
            },
            "Characteristics": {
               "type": "long"
            },
            "FileType": {
               "type": "long"
            },
            "Id": {
               "type": "string"
            },
            "Strings": {
               "type": "nested",
               "properties": {
                  "FileOffset": {
                     "type": "long"
                  },
                  "RO_BaseOfCode": {
                     "type": "long"
                  },
                  "SectionName": {
                     "type": "string"
                  },
                  "SectionOffset": {
                     "type": "long"
                  },
                  "String": {
                     "type": "string"
                  }
               }
            },
            "SubSystem": {
               "type": "long"
            }
         }
      }
   }
}

I've tested this using curl, I am sure this solves your problem.

Hope this helps!!

Upvotes: 1

Related Questions