【问题标题】:Elasticsearch: Already re-mapping but It still wont show all fieldsElasticsearch:已经重新映射,但它仍然不会显示所有字段
【发布时间】:2017-07-04 13:56:58
【问题描述】:

我只是想将我的 mongodb 与 ElasticSearch 同步。我已经完成了与河的同步,河已经工作了。但是ES不会显示所有字段,它只显示“_source”对象中的“_ts”字段:

请求: 获取 localhost:9200/test/orders/_search 回应:

{
    "took": 11,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 137,
        "max_score": 1,
        "hits": [
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58a3251f761f35a107724add",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58a340467f39c50f3a54c614",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58b8ec806f34179d7c7b2431",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58b8eff56f3417670f7b244a",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58b8f0af6f3417fb207b244c",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58b8f19a6f341761337b23da",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58b9320c6f3417bc1c7b23c7",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58b9339f6f341777237b23c6",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58b934ab6f341778237b23c7",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            },
            {
                "_index": "test",
                "_type": "orders",
                "_id": "58b96ef76f34174a4b7b23c8",
                "_score": 1,
                "_source": {
                    "_ts": 6438761296509796000
                }
            }
        ]
    }
}

我已经进行了重新映射,它显示了更新的映射。看到这个: 要求: 获取 localhost:9200/test/orders/_mapping 回复:

{
    "test": {
        "mappings": {
            "orders": {
                "properties": {
                    "_ts": {
                        "type": "long"
                    },
                    "activeDate": {
                        "type": "text"
                    },
                    "awbNumber": {
                        "type": "text"
                    },
                    "batchID": {
                        "type": "text"
                    },
                    "consignee": {
                        "properties": {
                            "id": {
                                "type": "text"
                            },
                            "name": {
                                "type": "text"
                            },
                            "phoneNumber": {
                                "type": "text"
                            }
                        }
                    },
                    "consigner": {
                        "properties": {
                            "id": {
                                "type": "text"
                            },
                            "name": {
                                "type": "text"
                            },
                            "phoneNumber": {
                                "type": "text"
                            }
                        }
                    },
                    "courier": {
                        "properties": {
                            "actualRate": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "id": {
                                "type": "integer"
                            },
                            "max_day": {
                                "type": "integer"
                            },
                            "min_day": {
                                "type": "integer"
                            },
                            "name": {
                                "type": "text"
                            },
                            "rate": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "rate_id": {
                                "type": "integer"
                            },
                            "rate_name": {
                                "type": "text"
                            },
                            "shipmentType": {
                                "type": "integer"
                            }
                        }
                    },
                    "creationDate": {
                        "type": "text"
                    },
                    "destination": {
                        "properties": {
                            "address": {
                                "type": "text"
                            },
                            "cityID": {
                                "type": "integer"
                            },
                            "cityName": {
                                "type": "text"
                            },
                            "id": {
                                "type": "integer"
                            },
                            "provinceID": {
                                "type": "integer"
                            },
                            "provinceName": {
                                "type": "text"
                            }
                        }
                    },
                    "driver": {
                        "properties": {
                            "feedback": {
                                "properties": {
                                    "comment": {
                                        "type": "text"
                                    },
                                    "score": {
                                        "type": "long"
                                    }
                                }
                            },
                            "id": {
                                "type": "long"
                            },
                            "isPaymentCollected": {
                                "type": "integer"
                            },
                            "name": {
                                "type": "text"
                            },
                            "phoneNumber": {
                                "type": "text"
                            },
                            "vehicleNumber": {
                                "type": "text"
                            },
                            "vehicleType": {
                                "type": "text"
                            }
                        }
                    },
                    "externalID": {
                        "type": "text"
                    },
                    "groupID": {
                        "type": "integer"
                    },
                    "id": {
                        "type": "text"
                    },
                    "isActive": {
                        "type": "long"
                    },
                    "isAutoTrack": {
                        "type": "integer"
                    },
                    "isCustomAWB": {
                        "type": "integer"
                    },
                    "isEscrow": {
                        "type": "integer"
                    },
                    "isLabelPrinted": {
                        "type": "integer"
                    },
                    "lastUpdatedDate": {
                        "type": "text"
                    },
                    "origin": {
                        "properties": {
                            "address": {
                                "type": "text"
                            },
                            "cityID": {
                                "type": "integer"
                            },
                            "cityName": {
                                "type": "text"
                            },
                            "id": {
                                "type": "integer"
                            },
                            "provinceID": {
                                "type": "integer"
                            },
                            "provinceName": {
                                "type": "text"
                            }
                        }
                    },
                    "package": {
                        "properties": {
                            "content": {
                                "type": "text"
                            },
                            "contents": {
                                "type": "integer"
                            },
                            "cubicalWeight": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "dimension": {
                                "properties": {
                                    "height": {
                                        "properties": {
                                            "UoM": {
                                                "type": "text"
                                            },
                                            "value": {
                                                "type": "integer"
                                            }
                                        }
                                    },
                                    "length": {
                                        "properties": {
                                            "UoM": {
                                                "type": "text"
                                            },
                                            "value": {
                                                "type": "integer"
                                            }
                                        }
                                    },
                                    "width": {
                                        "properties": {
                                            "UoM": {
                                                "type": "text"
                                            },
                                            "value": {
                                                "type": "integer"
                                            }
                                        }
                                    }
                                }
                            },
                            "fragile": {
                                "type": "integer"
                            },
                            "isConfirmed": {
                                "type": "integer"
                            },
                            "itemName": {
                                "type": "text"
                            },
                            "itemSubtype": {
                                "type": "integer"
                            },
                            "itemType": {
                                "type": "integer"
                            },
                            "pictureURL": {
                                "type": "text"
                            },
                            "price": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "type": {
                                "type": "integer"
                            },
                            "weight": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            }
                        }
                    },
                    "paymentType": {
                        "type": "text"
                    },
                    "pickUpTime": {
                        "type": "text"
                    },
                    "rates": {
                        "properties": {
                            "actualInsurance": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "long"
                                    }
                                }
                            },
                            "actualShipment": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "escrowCost": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "fulfillmentCost": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "insurance": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "long"
                                    }
                                }
                            },
                            "itemPrice": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "liability": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            },
                            "shipment": {
                                "properties": {
                                    "UoM": {
                                        "type": "text"
                                    },
                                    "value": {
                                        "type": "integer"
                                    }
                                }
                            }
                        }
                    },
                    "readyTime": {
                        "type": "text"
                    },
                    "shipmentStatus": {
                        "properties": {
                            "description": {
                                "type": "text"
                            },
                            "name": {
                                "type": "text"
                            },
                            "statusCode": {
                                "type": "integer"
                            },
                            "updateDate": {
                                "type": "text"
                            },
                            "updatedBy": {
                                "type": "text"
                            }
                        }
                    },
                    "source": {
                        "type": "text"
                    },
                    "specialID": {
                        "type": "text"
                    },
                    "stickerNumber": {
                        "type": "text"
                    },
                    "useInsurance": {
                        "type": "integer"
                    }
                }
            }
        }
    }
}

我希望我可以在“_source”字段中获取整个字段(不仅仅是单个“_ts”字段),它应该与我映射的内容相同。

我尝试删除索引并重新创建一个,但仍然没有成功。这种问题的任何线索。我真的很需要帮助,非常感谢。

【问题讨论】:

    标签: elasticsearch indexing elasticsearch-5 elasticsearch-river


    【解决方案1】:

    ElasticSearch 具有自行创建字段的行为。所以如果你这样做了

    PUT document/index/1
    {
        "id" : "1",
        "name" : "kashish",
        "phoneNumber" : "9740683281"
    }
    

    这将自动为您的索引创建字段。我要说明的是,如果由于某种原因显式定义字段不适合您,您可以清空索引(如果包含虚拟数据),然后只需放入 ES 将自动拾取的 json。

    【讨论】:

    • 您的意思是在创建索引后立即插入一个文档吗?我试过了,还是不行。
    • 不要创建文档或索引。只需提出请求而不创建任何文档和索引。它将自动选择给定的 json,并根据字段名称为您配置字段类型。希望对您有所帮助。
    • 抱歉,我没听懂。我没有在 ES 上创建文档,我在 mongodb shell 上创建了它,它会自动同步到 ES 中。我不知道如何不创建索引,但它会自动创建。你能给我一些关于如何自动创建索引的例子吗?谢谢@Kashish Verma
    • 你能给我一个关于 put 请求的简单例子吗?我还是ES的新手,一目了然。谢谢你
    • 我已经尝试过像您的第一个答案一样的 put 请求,是的,它显示了所有字段。但实际上它仍然无法解决我的问题。完成 put 请求后,我尝试将集合从另一个数据库复制到当前数据库,完成复制后,它们仍然没有显示所有字段。您对复制集合有任何想法,但仍然像 put 请求一样吗?
    猜你喜欢
    • 2018-06-21
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2022-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多