[英]elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'No handler for type [string] declared on field [texts]')
[英]Python + ElasticSearch: Mapper Parsing Exceptions for join field
我正在使用 ElasticSearch 8.3.2 來存儲我擁有的一些數據。 數據由代謝物和每種代謝物的幾個“研究”組成,每個研究又包含濃度值。 我還使用Python ElasticSearch 客戶端與后端通信,效果很好。 為了將代謝物與研究相關聯,我正在考慮使用此處所述的連接字段。
我已經定義了這個索引映射:
INDEXMAPPING_MET = {
"mappings": {
"properties": {
"id": {"type": "keyword"},
"entry_type": {"type": "text"},
"pc_relation": {
"type": "join",
"relations": {
"metabolite": "study"
}
},
"concentration": {
"type": "nested",
}
}
}
}
pc_relation
是這里的連接字段,代謝物是每個研究文檔的父文檔。 例如,我可以使用 Python 客戶端創建代謝物條目(父文檔)
self.client.index(index="metabolitesv2", id=metabolite, body=json.dumps({
#[... some other fields here]
"pc_relation": {
"name": "metabolite",
},
}))
但是,一旦我嘗試添加子文檔,我就會得到一個mapping_parser_exception
。 值得注意的是,我只在嘗試添加pc_relation
字段時遇到此異常,任何其他字段都可以正常工作,如果我省略連接字段,我可以創建文檔。 這是我正在嘗試創建的研究文檔的示例(在同一索引上):
self.client.index(index="metabolitesv2", id=study, body=json.dumps({
#[... some other fields here]
"pc_relation": {
"name": "study",
"parent": metabolite_id
},
}))
起初我以為可能存在一些打字問題,但不幸的是,將所有內容都轉換為字符串並沒有改變結果。 對於錯誤可能出在哪里的任何幫助,我真的很感激,因為我不確定問題出在哪里——從官方 ES 文檔和其他 Python+ES 項目中我可以看出,我並沒有做任何不同的事情。
嘗試過:創建一個帶有連接字段的索引,創建一個父文檔,創建一個與父文檔有連接關系的子文檔。 預期:文檔被創建並可以使用has_child
或has_parent
標簽查詢。 結果:嘗試創建子文檔時出現 MappingParserException
您需要在索引時為子文檔提供路由值。
路由值是強制性的,因為父文檔和子文檔必須在同一個分片上建立索引
默認情況下文檔的路由值是它的_id
,所以在實踐中你需要在索引子文檔時提供父文檔的_id
。
self.client.index(index="metabolitesv2", id=study, routing=metabolite, body=json.dumps({
#[... some other fields here]
"pc_relation": {
"name": "study",
"parent": metabolite_id
},
}))
PUT 75224800
{
"settings": {
"number_of_shards": 4
},
"mappings": {
"properties": {
"id": {
"type": "keyword"
},
"pc_relation": {
"type": "join",
"relations": {
"metabolite": "study"
}
}
}
}
}
PUT 75224800/_doc/1
{
"id": "1",
"pc_relation": "metabolite"
}
# No routing Id this is going to fail
PUT 75224800/_doc/2
{
"id": 2,
"pc_relation":{
"name": "study",
"parent": "1"
}
}
PUT 75224800/_doc/3
{
"id": "3",
"pc_relation": "metabolite"
}
PUT 75224800/_doc/4?routing=3
{
"id": 2,
"pc_relation":{
"name": "study",
"parent": "3"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.