Mohamed Ali
Mohamed Ali

Reputation: 782

"unknown key [_index] for create index"

Elasticsearch version : 7.1
Postman version : 7.8.0

My url looks like this

http://localhost:9200/menu

The error I am having:

{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "unknown key [index] for create index"
            }
        ],
        "type": "parse_exception",
        "reason": "unknown key [index] for create index"
    },
    "status": 400
}

Expected Result: Successfully able to enter new document into menu index.

I have been stuck with the issue for hours. I have tried different things but none works. What I am trying to do insert into elastic search using postman. I have already defined my mappings which looks like this below.

  "mappings": {
            "properties": {
                "input": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "output": {
                    "properties": {
                        "category": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "item": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "items": {
                            "properties": {
                                "category": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                        }
                                    }
                                },
                                "item": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                        }
                                    }
                                },
                                "modifiers": {
                                    "type": "text",
                                    "fields": {
                                        "keyword": {
                                            "type": "keyword",
                                            "ignore_above": 256
                                        }
                                    }
                                }
                            }
                        },
                        "modifiers": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "quantity": {
                            "type": "long"
                        }
                    }
                }
            }
        }

I pass in this following body to postman.

{
"index": {
    "_index": "catalog", "_type":"_doc"
    }}
{"input": "roast beef", "output": {
"category": "Sides", "item": "Large Roast-Beef Sandwich",   "modifiers": ["LG"], "quantity": 1
    }
}

Update 1: After chaning the body to this below.

{
    "index": {
        "_index": "catalog",
        "_type": "_doc"
    },
    "key":{
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
    }
}

I am now getting the error

{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "unknown key [index] for create index"
            }
        ],
        "type": "parse_exception",
        "reason": "unknown key [index] for create index"
    },
    "status": 400
}

Update 2: After changing the body to this

{       
        "_index": "catalog",
        "_type": "_doc",     
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
}

I get the error below

{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "unknown key [output] for create index"
            }
        ],
        "type": "parse_exception",
        "reason": "unknown key [output] for create index"
    },
    "status": 400
}

Upvotes: 0

Views: 10255

Answers (2)

Atur
Atur

Reputation: 1770

Make a PUT call to http://localhost:9200/menu/ (assuming you are running elastic at local on default port and index-name being 'menu').

In the body include your maaping as :

 {
    "mappings": {
        "properties": {
            "input": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "output": {
                "properties": {
                    "category": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "item": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "items": {
                        "properties": {
                            "category": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            },
                            "item": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            },
                            "modifiers": {
                                "type": "text",
                                "fields": {
                                    "keyword": {
                                        "type": "keyword",
                                        "ignore_above": 256
                                    }
                                }
                            }
                        }
                    },
                    "modifiers": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "quantity": {
                        "type": "long"
                    }
                }
            }
        }
    }
}

This will create the index, with following result(response):

 {
    "acknowledged": true,
    "shards_acknowledged": true,
    "index": "menu"
 }

Upvotes: 2

Gowri Pranith Kumar
Gowri Pranith Kumar

Reputation: 1685

the json body which you are sending is incorrect format. The Brackets arent closed in the proper order and the key name is missing for the body . Below is the correct json format

{       
        "_index": "catalog",
        "_type": "_doc"     
        "input": "roast beef",
        "output": {
            "category": "Sides",
            "item": "Large Roast-Beef Sandwich",
            "modifiers": [
                "LG"
            ],
            "quantity": 1
        }
}

Upvotes: 1

Related Questions