0

I'm trying to map a json structure on Elasticsearch but something seems to be wrong because when I launch the curl command from my Windows prompt nothing appends except the underscore pulsing.

I use this curl command:

curl -H "Content-Type: application/json" -XPUT http://localhost:9200/technogym -d "{\"mappings\":{\"id\":{\"type\":\"string\"},\"key\":{\"type\":\"string\"},\"value\":{\"type\":\"object\",\"properties\":{\"rev\":{\"type\":\"string\"}}},\"doc\":{\"type\":\"object\",\"properties\":{\"_id\":{\"type\":\"string\"},\"_rev\":{\"type\":\"string\"},\"userID\":{\"type\":\"string\"},\"conversation_id\":{\"type\":\"string\"},\"input\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"}}},\"output\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"}}},\"node_visited\":{\"type\":\"string\"},\"intents\":{\"properties\":{\"intent\":{\"type\":\"string\"},\"confidence\":{\"type\":\"string\"}}},\"entities\":{\"type\":\"object\",\"properties\":{\"entity\":{\"type\":\"string\"},\"location\":{\"type\":\"string\"},\"value\":{\"type\":\"string\"},\"confidence\":{\"type\":\"string\"}}},\"timestamp\":{\"type\":\"date\"}}}}}"

Here my jsonwith mapping (just to make it more readable):

EDIT

{"mappings": {
"_default_": {
  "properties": {
    "id": {
      "type": "string"
    },
    "key": {
      "type": "string"
    },
    "value": {
      "type": "object",
      "properties": {
        "rev": {
          "type": "string"
        }
      }
    },
    "doc": {
      "type": "object",
      "properties": {
        "_id": {
          "type": "string"
        },
        "_rev": {
          "type": "string"
        },
        "userID": {
          "type": "string"
        },
        "conversation_id": {
          "type": "string"
        },
        "input": {
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            }
          }
        },
        "output": {
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            }
          }
        },
        "node_visited": {
          "type": "string"
        },
        "intents": {
          "properties": {
            "intent": {
              "type": "string"
            },
            "confidence": {
              "type": "string"
            }
          }
        },
        "entities": {
          "type": "object",
          "properties": {
            "entity": {
              "type": "string"
            },
            "location": {
              "type": "string"
            },
            "value": {
              "type": "string"
            },
            "confidence": {
              "type": "string"
            }
          }
        },
        "timestamp": {
          "type": "date"
        }
      }
    }
  }
}}}

I don't know why I can't upload this mapping.

Thanks for any help.

0

2 Answers 2

1

create an index

curl -XPUT localhost:9200/technogym
{"acknowledged":true}

Then apply your mapping to whatever type you want, eg. technogym_type

curl -X PUT localhost:9200/technogym/technogym_type/_mapping -d '{
  "properties": {
    "id": {
      "type": "string"
    },
    "key": {
      "type": "string"
    },
    "value": {
      "type": "object",
      "properties": {
        "rev": {
          "type": "string"
        }
      }
    },
    "doc": {
      "type": "object",
      "properties": {
        "_id": {
          "type": "string"
        },
        "_rev": {
          "type": "string"
        },
        "userID": {
          "type": "string"
        },
        "conversation_id": {
          "type": "string"
        },
        "input": {
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            }
          }
        },
        "output": {
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            }
          }
        },
        "node_visited": {
          "type": "string"
        },
        "intents": {
          "properties": {
            "intent": {
              "type": "string"
            },
            "confidence": {
              "type": "string"
            }
          }
        },
        "entities": {
          "type": "object",
          "properties": {
            "entity": {
              "type": "string"
            },
            "location": {
              "type": "string"
            },
            "value": {
              "type": "string"
            },
            "confidence": {
              "type": "string"
            }
          }
        },
        "timestamp": {
          "type": "date"
        }
      }
    }
  }
}'

{"acknowledged":true}

But if you dynamically want to create index and mappings, just fix your JSON document where it needs mappings (plural) and followed by the name of the type you want. (type equivalent to RDBMS table name)

curl -X PUT localhost:9200/technogym1 -d '
{
  "mappings": {
    "technogym_type1": {
      "properties": {
        "id": {
          "type": "string"
        },
        "key": {
          "type": "string"
        },
        "value": {
          "type": "object",
          "properties": {
            "rev": {
              "type": "string"
            }
          }
        },
        "doc": {
          "type": "object",
          "properties": {
            "_id": {
              "type": "string"
            },
            "_rev": {
              "type": "string"
            },
            "userID": {
              "type": "string"
            },
            "conversation_id": {
              "type": "string"
            },
            "input": {
              "type": "object",
              "properties": {
                "text": {
                  "type": "string"
                }
              }
            },
            "output": {
              "type": "object",
              "properties": {
                "text": {
                  "type": "string"
                }
              }
            },
            "node_visited": {
              "type": "string"
            },
            "intents": {
              "properties": {
                "intent": {
                  "type": "string"
                },
                "confidence": {
                  "type": "string"
                }
              }
            },
            "entities": {
              "type": "object",
              "properties": {
                "entity": {
                  "type": "string"
                },
                "location": {
                  "type": "string"
                },
                "value": {
                  "type": "string"
                },
                "confidence": {
                  "type": "string"
                }
              }
            },
            "timestamp": {
              "type": "date"
            }
          }
        }
      }
    }
  }
}'
{"acknowledged":true,"shards_acknowledged":true}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you ;). Yes I've edited with the right json because in my right one there is "mappings" instead of "mapping". Thanks for the help again it has turned out very usefull
great that it worked for you. if you want to create index first (equivalent to database name in RDBMS) and then type mapping, then follow first answer otherwise, your way of doing is correct too. You can verify mappings with http://localhost:9200/technogym1/technogym_type1/_mapping?pretty=true
1

You need to change mapping to mappings.

{
"mappings": {                ==> change this
"_default_": {
"properties": {
"id": {
  "type": "string"
},
"key": {
  "type": "string"
},
"value": {
  "type": "object",
  "properties": {
    "rev": {
      "type": "string"
    }
  }
},
"doc": {
  "type": "object",
  "properties": {
    "_id": {
      "type": "string"
    },
    "_rev": {
      "type": "string"
    },
    "userID": {
      "type": "string"
    },
    "conversation_id": {
      "type": "string"
    },
    "input": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string"
        }
      }
    },
    "output": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string"
        }
      }
    },
    "node_visited": {
      "type": "string"
    },
    "intents": {
      "properties": {
        "intent": {
          "type": "string"
        },
        "confidence": {
          "type": "string"
        }
      }
    },
    "entities": {
      "type": "object",
      "properties": {
        "entity": {
          "type": "string"
        },
        "location": {
          "type": "string"
        },
        "value": {
          "type": "string"
        },
        "confidence": {
          "type": "string"
        }
      }
    },
    "timestamp": {
      "type": "date"
       }
       }}}}}}

1 Comment

Sorry you are right, I've posted a wrong json but in my right one is mappings. Now I edit the question. Thanks

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.