(我正在使用Elasticsearch 1.5.2的新副本执行此操作)
我已经定义了一个自定义分析器,它正在工作:
curl -XPUT 127.0.0.1:9200/test -d '{
"settings": {
"index": {
"analysis": {
"tokenizer": {
"UrlTokenizer": {
"type": "pattern",
"pattern": "https?://([^/]+)",
"group": 1
}
},
"analyzer": {
"accesslogs": {
"tokenizer": "UrlTokenizer"
}
}
}
}
}
}'; echo
curl '127.0.0.1:9200/test/_analyze?analyzer=accesslogs&text=http://192.168.1.1/123?a=2#1111' | json_pp
Run Code Online (Sandbox Code Playgroud)
现在我将它应用于索引:
curl -XPUT 127.0.0.1:9200/test/accesslogs/_mapping -d '{
"accesslogs" : {
"properties" : {
"referer" : { "type" : "string", "copy_to" : "referer_domain" },
"referer_domain": {
"type": "string",
"analyzer": "accesslogs"
}
}
}
}'; echo
Run Code Online (Sandbox Code Playgroud)
从映射我可以看到它们都被应用.
现在我尝试插入一些数据,
curl 127.0.0.1:9200/test/accesslogs/ -d '{
"referer": "http://192.168.1.1/aaa.php",
"response": 100
}';echo
Run Code Online (Sandbox Code Playgroud)
并且该copy_to字段,也referer_domain就是未生成,如果我尝试添加具有该名称的字段,则也不应用标记化器.
有任何想法吗?
copy_to 但是,你假设,因为你没有看到生成的字段,它不存在.
当您返回文档时(GET /test/accesslogs/1例如),您没有看到下面的字段_source.它包含已编制索引的原始文档.并且您没有索引任何referer_domain字段,只是referer和response.这就是你没有看到它的原因.
但Elasticsearch 确实在倒排索引中创建了该字段.如果存储它,您可以使用它来查询,计算或检索.
让我举例说明我的发言:
GET /test/accesslogs/_search
{
"fielddata_fields": ["referer","response","referer_domain"]
}
Run Code Online (Sandbox Code Playgroud)
"referer_domain": {
"type": "string",
"analyzer": "accesslogs",
"store" : true
}
Run Code Online (Sandbox Code Playgroud)
有了这个:
GET /test/accesslogs/_search
{
"fields": ["referer","response","referer_domain"]
}
Run Code Online (Sandbox Code Playgroud)
总之,copy_to修改索引文档,而不是源文档.您可以查询具有该字段的文档,它将起作用,因为查询会查看倒排索引.如果要检索该字段,还需要存储它.但是您不会在该_source字段中看到该字段,因为它_source是已编制索引的初始文档.并且初始文档不包含referer_domain.
| 归档时间: |
|
| 查看次数: |
2223 次 |
| 最近记录: |