具有映射的动态类型 [英] Dynamic Type with Mappings

查看:93
本文介绍了具有映射的动态类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据结构非常通用。几乎任何类型的数据适合我的数据结构。

 文档{
id:12345678,
fields:
[{
name:书名,
value:Harry Potter,
type:string

{
name:price,
value:34.50,
type:float
}]
}

另一个文档可能是这样的:

 文件{
id:123456790,
fields:
[{
name:博客标题,
value:我真棒博客,
type:string
}]
}
/ pre>

此数据可以更改,字段可以有任何类型和名称。
我如何动态创建模板映射,以便映射的类型由我的数据中的类型的值设置?
例如值:34.50,类型:float
同时数据value:哈利波特,键入:string



我已经看到已经在ES中完成了,但是我无法让我的头发做一个实际使用文档中指定的type值的映射来实际设置该值的正确类型。



在某种意义上,指定类型对于我来说特别有用,例如,可以在同一数据结构上具有例如位置类型,日期类型,整数或...。



我一直在寻找任何内容在线或在书籍,但迄今为止没有。
这是甚么可能的?

解决方案

首先,您将要使用嵌套的类型,以确保名称上的查询/过滤器不会与



其次,您不能具有相同字段名称的不同类型,在本例中为value。因此,您需要更改您发送给Elasticsearch的邮件的结构。



当您说任何类型时,您是否可以控制类型?如果你这样做,你可以做一些像date_value,location_value,float_value(或类似的东西)等)的字段。 string_value并不是一件好事。它有什么分析仪?可能会有一个为其目的命名的类型,例如keyword_value(例如,您可能想要面对的东西),name_value(可以具有模糊支持),text_value(分析正确的搜索)等等。



我做了一个可运行的例子,您可以在这里玩: https:// www .found.no / play / gist / 7596633


My data is structure is very generic. and almost any type of data fits in my datastructure.

Document{
    "id" : 12345678,
    "fields" : 
        [{
            "name" : "Book title",
            "value" : "Harry Potter",
            "type" : "string"
        },
        {
            "name" : "price",
            "value" : 34.50,
            "type" : "float"
        }]
}

Another Document could be like this:

Document{
    "id" : 123456790,
    "fields" : 
        [{
            "name" : "Blog title",
            "value" : "My awesome blog",
            "type" : "string"
        }]
}

This data can change and fields could have any type and names. How can I dynamically create a template mapping so that the "type" for mapping is set by the value of the "type" in my data? e.g. value: 34.50, type: float at the same time the same data "value" : "Harry Potter", type : string

I have seen that is has been done in ES but I can't get my head around making a mapping that actually uses the value of "type" specified in the document to actually set the correct type for the value.

Specifying types is particularly useful for me in a sense I can have for example, location type, date type, integer or ... on the same data structure.

I have been trying to find any content either online or in books but so far nothing. Is this even possible?

解决方案

First, you'll want to use nested types to make sure a query/filter on name is not mingled with values of another field of the same document.

Secondly, you cannot have different types with the same field name, in this case "value". Thus, you will need to change the structure of the doucments you send to Elasticsearch a bit.

When you say "any type", will you have control on the number of types? If you do, you can do things like having fields called "date_value", "location_value", "float_value" (or something similar) and so on. "string_value" is not really a good one. What analyzer will it have? It might be better to have a type named for its purpose, e.g. "keyword_value" (for things you might want to facet on, for example), "name_value" (which can have fuzzy support), "text_value" (analyzed for proper search), and so on.

I made a runnable example you can play with here: https://www.found.no/play/gist/7596633

这篇关于具有映射的动态类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆