代码之家  ›  专栏  ›  技术社区  ›  Enoy

严格使用ElasticSearch映射

  •  0
  • Enoy  · 技术社区  · 4 年前

    我们正在使用ElasticSearch进行开发。我们创建了两个索引:notificacionespush\u anadirdispositivo,用于存储新用户的设备;notificacionespush\u crearnotificacion,用于存储与已创建新通知相关的信息。

    通知spush\u anadirdispositivo的映射:

    {
        "notificacionespush_anadirdispositivo": {
            "mappings": {
                "properties": {
                    "descripcionresultado": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "fechahora": {
                        "type": "date",
                        "format": "dd/MM/yyyy HH:mm:ss"
                    },
                    "idapp": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "iddispositivo": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "idioma": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "numexpediente": {
                        "type": "long"
                    },
                    "resultado": {
                        "type": "long"
                    },
                    "tiponotificacion": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "usuario": {
                        "type": "long"
                    }
                }
            }
        }
    }
    

    推送凭证映射:

    {
        "notificacionespush_crearnotificacion": {
            "mappings": {
                "properties": {
                    "descripcionresultado": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "fechahora": {
                        "type": "date",
                        "format": "dd/MM/yyyy HH:mm:ss"
                    },
                    "idapp": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "idioma": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "numexpediente": {
                        "type": "long"
                    },
                    "resultado": {
                        "type": "long"
                    },
                    "tiponotificacion": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        }
    }
    

    我们对这个主题很感兴趣和好奇,因为我们发现,如果我们向索引notificationspush\u anadirdispositivo发送一个帖子,其中包含一个JSON,表示一条信息,该信息具有notificationspush\u crearnotificicon的映射,那么它就被接受了。

    {
        "took": 513,
        "timed_out": false,
        "_shards": {
            "total": 1,
            "successful": 1,
            "skipped": 0,
            "failed": 0
        },
        "hits": {
            "total": {
                "value": 4,
                "relation": "eq"
            },
            "max_score": 1.0,
            "hits": [
                {
                    "_index": "notificacionespush_anadirdispositivo",
                    "_type": "_doc",
                    "_id": "gT1DnHABgf__-U4-DNkw",
                    "_score": 1.0,
                    "_source": {
                        "usuario": 665365335,
                        "iddispositivo": "SuperID",
                        "idapp": "miHistoria",
                        "fechahora": "02/03/2020 17:20:04",
                        "resultado": -2,
                        "descripcionresultado": "Ya existe ese dispositivo asociado al expediente con el que se pretende registrar"
                    }
                },
                {
                    "_index": "notificacionespush_anadirdispositivo",
                    "_type": "_doc",
                    "_id": "RD1EnHABgf__-U4-U9re",
                    "_score": 1.0,
                    "_source": {
                        "usuario": 11473564,
                        "iddispositivo": "PRE4283599e-4718-4482-8dd5-733c29156cc2",
                        "idapp": "miCitaPrevia",
                        "fechahora": "27/02/2020 16:27:14"
                    }
                },
                {
                    "_index": "notificacionespush_anadirdispositivo",
                    "_type": "_doc",
                    "_id": "wj1MnHABgf__-U4-h9ui",
                    "_score": 1.0,
                    "_source": {
                        "usuario": 11473564,
                        "iddispositivo": "PRE4283599e-4718-4482-8dd5-733c29156cc2",
                        "idapp": "miCitaPrevia",
                        "fechahora": "27/02/2020 16:27:14"
                    }
                },
                {
                    "_index": "notificacionespush_anadirdispositivo",
                    "_type": "_doc",
                    "_id": "Uj1lnHABgf__-U4-COAX",
                    "_score": 1.0,
                    "_source": {
                        "idapp": "5cf57b56-c3b4-4a0d-8938-4ac4466f93af",
                        "numexpediente": 123456789,
                        "idioma": "es",
                        "tiponotificacion": "citafuturaAP",
                        "fechahora": "20/02/2020 10:52:57",
                        "resultado": 0,
                        "descripcionresultado": "{\"id\":\"\",\"recipients\":0,\"errors\":[\"All included players are not subscribed\"]}"
                    }
                }
            ]
        }
    }
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   Daniel Schneiter    4 年前

    只需添加 "dynamic": "strict"

    (参见Elasticsearch参考: dynamic