Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 如何定义ElasticSearch动态模板?_Templates_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Mappings - Fatal编程技术网 elasticsearch,mappings,Templates,elasticsearch,Mappings" /> elasticsearch,mappings,Templates,elasticsearch,Mappings" />

Templates 如何定义ElasticSearch动态模板?

Templates 如何定义ElasticSearch动态模板?,templates,elasticsearch,mappings,Templates,elasticsearch,Mappings,我试图在弹性搜索中定义动态模板,以便为当前未定义的翻译属性自动设置分析器 例如,以下操作正是我想要的,即设置lang.en.title以使用英语分析器: PUT /cl { "mappings" : { "titles" : { "properties" : { "id" : { "type" : "integer", "index"

我试图在弹性搜索中定义动态模板,以便为当前未定义的翻译属性自动设置分析器

例如,以下操作正是我想要的,即设置lang.en.title以使用英语分析器:

PUT /cl 
{
    "mappings" : {
        "titles" : {
            "properties" : {
                "id" : {
                    "type" : "integer",
                    "index" : "not_analyzed"
                },
                "lang" : {
                    "type" : "object",
                    "properties" : {
                        "en" : {
                            "type" : "object",
                            "properties" : {
                                "title" : {
                                        "type" : "string",
                                        "index" : "analyzed",
                                        "analyzer" : "english"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
哪个词干的lang.en.title与预期的一样,例如

GET /cl/_analyze?field=lang.en.title&text=knocked

{
   "tokens": [
      {
         "token": "knock",
         "start_offset": 0,
         "end_offset": 7,
         "type": "<ALPHANUM>",
         "position": 1
      }
   ]
}
英语分析器没有被应用,因为lang.en.title的词干没有达到预期-

GET /cl/_analyze?field=lang.en.title&text=knocked

{
   "tokens": [
      {
         "token": "knocked",
         "start_offset": 0,
         "end_offset": 7,
         "type": "<ALPHANUM>",
         "position": 1
      }
   ]
}
GET/cl/\u analyze?field=lang.en.title&text=1
{
“代币”:[
{
“令牌”:“敲门”,
“起始偏移量”:0,
“端部偏移”:7,
“类型”:“,
“职位”:1
}
]
}

我错过了什么?:)

您的动态模板定义正确。问题是,在动态模板应用适当的映射之前,您需要使用
lang.en.title
字段为文档编制索引。我在本地运行了与您在上面的问题中定义的相同的动态映射,得到了与您相同的结果

但是,我在索引中添加了一个文档

POST /cl/titles/1
{
    "lang.en.title": "Knocked out"
}
添加文档后,我再次运行分析器,得到了预期的输出:

GET /cl/_analyze?field=lang.en.title&text=knocked

{
   "tokens": [
      {
         "token": "knock",
         "start_offset": 0,
         "end_offset": 7,
         "type": "<ALPHANUM>",
         "position": 1
      }
   ]
}
GET/cl/\u analyze?field=lang.en.title&text=1
{
“代币”:[
{
“令牌”:“敲门”,
“起始偏移量”:0,
“端部偏移”:7,
“类型”:“,
“职位”:1
}
]
}
索引需要插入一个文档,以便能够为插入的字段执行定义的映射模板。一旦索引中存在该字段并应用了动态映射,
\u analyze
API调用将按预期执行

GET /cl/_analyze?field=lang.en.title&text=knocked

{
   "tokens": [
      {
         "token": "knock",
         "start_offset": 0,
         "end_offset": 7,
         "type": "<ALPHANUM>",
         "position": 1
      }
   ]
}