json - 无法加载json映射Elasticsearch

标签 json elasticsearch

我正在尝试在Elasticsearch上映射json结构,但是似乎有些问题,因为当我从Windows提示符启动curl命令时,除了下划线脉冲外没有任何追加。

我使用以下curl命令:

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\"}}}}}"

这是我的jsonwith映射(只是为了使其更具可读性):

编辑
{"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"
        }
      }
    }
  }
}}}

我不知道为什么不能上传此映射。

谢谢你的帮助。

最佳答案

创建一个索引

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

然后将您的映射应用于所需的任何类型,例如。 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}

但是,如果您要动态创建索引和映射,只需将JSON文档固定在需要mappings(复数)的位置,然后加上所需类型的名称即可。 (类型等效于RDBMS表名)
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}

关于json - 无法加载json映射Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43976024/

相关文章:

elasticsearch - 使用HTTPS +基本身份验证让Logstash与Elastic Search对话

elasticsearch - 每当我更新文档时,Elasticsearch会自动为文档重新编制索引吗

ios - iOS,如何在数组中的dic中循环dic以替换空字符串的空值

c# - asp.net core 1.0 web api使用camelcase

php - 从 vb.Net 向服务器上的 PHP 发送数据数组

php - 如何获取与以下 JSON 对象的距离值?

Java Elasticsearch : Search term like

elasticsearch - elasticsearch标记化方面的术语

javascript - json编码多维数组获取值

sorting - ElasticSearch 深度嵌套排序/评分