我有一些奇怪的行为弹性搜索。我使用自定义分析器和自定义标记器,它在空格、+、-的情况下溢出单词。
当我在寻找
{
"query": {
"match_phrase_prefix": {
"name.default": {
"query": "paris oly"
}
}
}
}我得到了预期的结果巴黎奥林匹亚等等..。但当我在寻找
{
"query": {
"match_phrase_prefix": {
"name.default": {
"query": "paris ol"
}
}
}
}我完全没有结果。
设置:
"analysis": {
"analyzer": {
"customAnalyzer": {
"type": "custom",
"filter": "lowercase",
"tokenizer": "customTokenizer"
},
"tokenizer": {
"customTokenizer": {
"pattern": "[\\+\\s-]",
"type": "pattern"
}
}
}实地测绘:
{
"name": {
"properties": {
"default": {
"type": "string",
"analyzer": "customAnalyzer"
}
}
}
}文档的部分示例(所请求的字段):
{
"name": {
"jp": "パリ オリンピア (劇場)",
"default": "Paris Olympia",
}
}
{
"TYPE_NAME": {
"dynamic_templates": [
{
"name": {
"path_match": "*name.*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"analyzer": "customAnalyzer"
}
}
}
],
"properties": {
"point": {
"type": "geo_point"
}
}
}
}发布于 2015-02-05 17:16:10
当我试着测试你发布的内容时,它对我起了作用。我会张贴我做了什么,你可以看看它,看看你是否可以找出有什么不同的设置,如果你有更多的问题,我会尽力帮助。
我使用您发布的映射和分析器/标记器创建了一个索引,然后添加了您发布的文档:
DELETE /test_index
PUT /test_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"tokenizer": {
"customTokenizer": {
"pattern": "[\\+\\s-]",
"type": "pattern"
}
},
"analyzer": {
"customAnalyzer": {
"type": "custom",
"filter": "lowercase",
"tokenizer": "customTokenizer"
}
}
}
},
"mappings": {
"doc": {
"properties": {
"name": {
"properties": {
"default": {
"type": "string",
"analyzer": "customAnalyzer"
}
}
}
}
}
}
}
PUT /test_index/doc/1
{
"name": {
"jp": "パリ オリンピア (劇場)",
"default": "Paris Olympia"
}
}然后,您发布的任何一个查询都会为我返回文档:
POST /test_index/_search
{
"query": {
"match_phrase_prefix": {
"name.default": {
"query": "paris oly"
}
}
}
}
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.38356602,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 0.38356602,
"_source": {
"name": {
"jp": "パリ オリンピア (劇場)",
"default": "Paris Olympia"
}
}
}
]
}
}或
POST /test_index/_search
{
"query": {
"match_phrase_prefix": {
"name.default": {
"query": "paris ol "
}
}
}
}
...
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.38356602,
"hits": [
{
"_index": "test_index",
"_type": "doc",
"_id": "1",
"_score": 0.38356602,
"_source": {
"name": {
"jp": "パリ オリンピア (劇場)",
"default": "Paris Olympia"
}
}
}
]
}
}为了方便起见,下面是我使用的代码:
http://sense.qbox.io/gist/4e58344580dcf01299f7cc2199d0fb7694d2a051
所以肯定还有别的事情要发生。你能分辨出你的设置和我的尝试有什么不同吗?
编辑:我必须切换令牌程序和分析器的顺序,因为否则会出错。所以你可能想调查一下。
https://stackoverflow.com/questions/28322434
复制相似问题