首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹性搜索phrase_prefix预期结果

弹性搜索phrase_prefix预期结果
EN

Stack Overflow用户
提问于 2015-02-04 13:18:22
回答 1查看 695关注 0票数 1

我有一些奇怪的行为弹性搜索。我使用自定义分析器和自定义标记器,它在空格、+、-的情况下溢出单词。

当我在寻找

代码语言:javascript
复制
{
  "query": {
    "match_phrase_prefix": {
      "name.default": {
        "query": "paris oly"
      }
    }
  }
}

我得到了预期的结果巴黎奥林匹亚等等..。但当我在寻找

代码语言:javascript
复制
{
  "query": {
    "match_phrase_prefix": {
      "name.default": {
        "query": "paris ol"
      }
    }
  }
}

我完全没有结果。

设置:

代码语言:javascript
复制
     "analysis": {
           "analyzer": {
              "customAnalyzer": {
                 "type": "custom",
                 "filter": "lowercase",
                 "tokenizer": "customTokenizer"
              },
           "tokenizer": {
              "customTokenizer": {
                 "pattern": "[\\+\\s-]",
                 "type": "pattern"
              }
           }
        }

实地测绘:

代码语言:javascript
复制
{
    "name": {
              "properties": {
                        "default": {
                        "type": "string",
                        "analyzer": "customAnalyzer"
                 }
            }
        }
}

文档的部分示例(所请求的字段):

代码语言:javascript
复制
 { 
"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"
        }
      }
     }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-05 17:16:10

当我试着测试你发布的内容时,它对我起了作用。我会张贴我做了什么,你可以看看它,看看你是否可以找出有什么不同的设置,如果你有更多的问题,我会尽力帮助。

我使用您发布的映射和分析器/标记器创建了一个索引,然后添加了您发布的文档:

代码语言:javascript
复制
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"
   }
}

然后,您发布的任何一个查询都会为我返回文档:

代码语言:javascript
复制
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"
               }
            }
         }
      ]
   }
}

代码语言:javascript
复制
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

所以肯定还有别的事情要发生。你能分辨出你的设置和我的尝试有什么不同吗?

编辑:我必须切换令牌程序和分析器的顺序,因为否则会出错。所以你可能想调查一下。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28322434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档