我想将一些非常复杂的文档存储在弹性文件中以检索它们并使它们可搜索。我不知道数据的整个结构,所以我想弹性地“吞噬”我放入的所有数据,但定义一些索引字段以使搜索成为可能。
一旦我为弹性提供了映射,我就会出错,如果我不定义映射,我担心索引会变得太大,因为弹性会索引太多。
我使用php创建索引,但是归结为:
PUT localhost:9200/name-of-index
{
"mappings": {
"_doc": {
"properties": {
"title": {
"type": "text"
}
}
}
}
}
然后-当我添加一个对象以测试所有内容时,我将收到以下错误:
状态400
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [name-of-index] as the final mapping would have more than 1 type: [_doc, 2187]"
}
],
"type": "illegal_argument_exception",
"reason": "Rejecting mapping update to [name-of-index] as the final mapping would have more than 1 type: [_doc, 2187]"
},
"status": 400
}
我用来发布文档的命令是关于:
POST localhost:9200/name-of-index/2187
{
"title": "some title",
"otherField": "other value",
"obj": {
"nestedProp": "nestedValue",
"deepObj": {
"someStorage": [
...
{
"someVeryDeepProp": 1
}
...
]
}
},
"obj2": [
"str1",
"str2"
]
}
节点名称当然不是真实的,而且结构要复杂得多。但我怀疑这是造成我问题的原因。
那么我该如何定义部分索引并将其他所有内容保持原样?
更新:我忘记了一些弹性信息。
{
"name" : "KNJ_3Eg",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "4M9p8XiaQHKPz7N2AAuVlw",
"version" : {
"number" : "6.6.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "a9861f4",
"build_date" : "2019-01-24T11:27:09.439740Z",
"build_snapshot" : false,
"lucene_version" : "7.6.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
答案 0 :(得分:0)
好的,那只是一个愚蠢的错误,我忘了添加类型。
因此添加文档的正确请求应该是:
POST localhost:9200/name-of-index/_doc/2187
{
"title": "some title",
"otherField": "other value",
"obj": {
"nestedProp": "nestedValue",
"deepObj": {
"someStorage": [
...
{
"someVeryDeepProp": 1
}
...
]
}
},
"obj2": [
"str1",
"str2"
]
}
我猜从版本7开始,它将不再使用“ _doc”,因为类型通常被弃用。