首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹性搜索,小写搜索不起作用

弹性搜索,小写搜索不起作用
EN

Stack Overflow用户
提问于 2017-07-01 02:22:43
回答 2查看 469关注 0票数 0

我正在尝试使用前缀再次搜索内容,如果我搜索二极管,我得到的结果与二极管不同。当二极管和二极管都返回相同的结果时,如何让ES返回结果?这是我在ES中使用的映射和设置。

代码语言:javascript
复制
"settings":{
   "analysis": {
   "analyzer": {
      "lowercasespaceanalyzer": {
      "type": "custom",
       "tokenizer": "whitespace",
       "filter": [
         "lowercase"
       ]
     }
   }
  }   
 },
"mappings": {
"articles": {
  "properties": {
    "title": {
      "type": "text"
    },
    "url": {
      "type": "keyword",
      "index": "true"
    },
    "imageurl": {
      "type": "keyword",
      "index": "true"
    },
    "content": {
      "type": "text",
      "analyzer" : "lowercasespaceanalyzer",
      "search_analyzer":"whitespace"
      },
    "description": {
      "type": "text"
    },
    "relatedcontentwords": {
      "type": "text"
    },
    "cmskeywords": {
      "type": "text"
    },
    "partnumbers": {
      "type": "keyword",
      "index": "true"
    },
    "pubdate": {
      "type": "date"
     }
    }
   }
 }

 here is an example of the query I use 
 POST _search
 {
   "query": {
        "bool" : {
            "must" : {
                "prefix" : { "content" : "capacitance" }
        }
     }
  }
 }
EN

回答 2

Stack Overflow用户

发布于 2017-07-02 12:09:40

在您的索引中将不会有Diode一词。因此,如果你想得到相同的结果,你应该让你的查询上下文由相同的分析器来分析。

您可以像这样使用Query string query

代码语言:javascript
复制
"query_string" : {
        "default_field" : "content",
        "query" : "Diode",
        "analyzer" :  "lowercasespaceanalyzer"
    }

更新

您可以在查询之前分析上下文。

代码语言:javascript
复制
AnalyzeResponse resp = client.admin().indices()
                             .prepareAnalyze(index, text)
                             .setAnalyzer("lowercasespaceanalyzer")
                             .get();
String analyzedContext = resp.getTokens().get(0);
...

然后使用analyzedContext作为新的查询上下文。

票数 0
EN

Stack Overflow用户

发布于 2017-07-04 01:45:19

这是因为您在搜索时和索引时使用了两个不同的分析器。因此,当您在搜索时输入查询"Diod“时,因为您使用了”空白“分析器,所以您的查询被解释为"Diod”。但是,因为您在索引时使用了"lowercasespaceanalyzer“,所以"diod”将被索引为"Diod“。只需在搜索和索引时使用相同的分析器,或者使用小写字符串的分析器,因为默认的“空白”分析器不会https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-whitespace-analyzer.html

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

https://stackoverflow.com/questions/44852735

复制
相关文章

相似问题

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