0

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
            )

1 Answer 1

1

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!!

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks again. I tried the above mapping to create an index but when I check the mapping it does not show the "Strings" of a type "nested" in it.
It works for me, maybe there is some problem while doing this with python libary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.