弹性搜索中的部分词搜索的自定义类型 [英] Custom type for partial word search in Elastic Search

查看:1094
本文介绍了弹性搜索中的部分词搜索的自定义类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很紧张的弹出搜索演示的时间表。



我已经设置了我的数据库,使用JDBC输入与Logstash并开始索引数据库表。它的一切工作都在一定程度上正常。但部分单词搜索不起作用。在弹性文件中快速搜索,建议使用nGram滤波器和干扰源。因为我没有得到干扰,我按照ngram过滤器的路径。



以下是我的索引映射,



  {settings:{ :{analyzer:{translation_index_analyzer:{type:custom,tokenizer:standard,filter:standard,lowercase,translation},translation_search_analyzer :custom,tokenizer:standard,filter:standard,smallcase}},filter:{translation:{type:nGram,min-gram ,max-gram:{type:type:{type:string,index_analyzer:translation_index_analyzer, search_analyzer:translation_search_analyzer}}},employee:{properties:{birth_date:{ type:date,format:yyyy-MM-dd HH:mm:ss ZZ},emp_no:{type:long,index:not_analyzed first_name:{type:myType},gender:{type:string,index:not_analyzed},hire_date:{type:date :yyyy-MM-dd HH:mm:ss ZZ},last_name:{type:string}}}}  



我宁愿猜到类型映射,因为我需要这样的东西。不知道这是否正确。



当我发布这个我收到错误



  {error {root_cause:[{type:mapper_parsing_exception,reason:search_analyzer设置时必须设置分析器字段[myType],type:mapper_parsing_exception,reason无法解析映射[type]:在search_analyzer设置时必须设置分析仪[myType],causes_by:{type:mapper_parsing_exception,reason:必须设置field字段[myType]当search_analyzer设置为}},status:400}  



任何线索我错了吗?



更新:我的弹性版本是2.2

从index_analyzer更改为分析仪发出不同的错误



  {error:{root_cause:[{type:mapper_parsing_exception,reason:字段[first_name]}],type:mapper_parsing_exception,reason:无法解析映射[employee]:在[first_name]字段上声明的类型为[myType]的处理程序键入:mapper_parsing_exception,reason:在字段[first_name]上声明的类型为[myType]的处理程序}},status:400}  

/ div>



最终解决方案:
嗯,我的问题是定义一个类型。我将忽略这一刻,但部分搜索工作与以下设置



  {settings:{analysis:{analyzer {my_ngram_analyzer:{tokenizer:my_ngram_tokenizer}},tokenizer:{my_ngram_tokenizer:{type:nGram,min_gram:3,max_gram:12  yyyy-MM-dd HH:mm:ss ZZ}, emp_no:{type:long,index:not_analyzed},first_name:{type:string,analyzer:my_ngram_analyzer,search_analyzer:my_ngram_analyzer} ,gender:{type:string,index:not_analyzed},hire_date:{type:date,format:yyyy-MM-dd HH: ssZZ},last_name:{type:string,analyzer:my_ngram_analyzer,search_analyzer:my_ngram_analyzer}}}}}  

解决方案

我的猜测,更改 index_analyzer with analyzer




  • 这取决于你的弹性搜索版本



编辑



我不熟悉创建类型,但您可以使用 first_name 相关分析器:

 first_name:{
type:string,
:translation_index_analyzer,
search_analyzer:translation_search_analyzer
},


I am in a tight schedule for a demo with Elastic Search.

I have setup my database, used JDBC input with Logstash and started indexing database tables. Its all working fine for some extent. But partial word search is not working. A quick search in Elastic documents suggested nGram filters and stemmers. Since I didn't get stemmers I followed the path of ngram filters.

Following is my index mapping,

{
 "settings" : {
	"analysis" : {
		"analyzer" : {
			"translation_index_analyzer" : {
				"type" : "custom",
				"tokenizer" : "standard",
				"filter" : "standard, lowercase, translation"
			},
			"translation_search_analyzer" : {
				"type" : "custom",
				"tokenizer" : "standard",
				"filter" : "standard, lowercase"
			}		
		},
		"filter" : {
			"translation" : {
				"type" : "nGram",
				"min-gram" : 3,
				"max-gram" : 12
			}
		}
    	}
 }, 
 "mappings" : {
        "type" : {
		"properties" : {
		     "myType" : {
			"type" : "string",
                        "index_analyzer" : "translation_index_analyzer",
                        "search_analyzer" : "translation_search_analyzer"
		     }	
		}
        }, 
        "employee" : {
            "properties" : {
                      "birth_date": {
                             "type": "date",
                            "format" : "yyyy-MM-dd HH:mm:ss ZZ"
          },
          "emp_no": {
                   "type": "long",
                    "index" : "not_analyzed"
          },
          "first_name": {
            "type": "myType"
          },
          "gender": {
            "type": "string",
              "index" : "not_analyzed"
          },
          "hire_date": { 
                             "type": "date",
                            "format" : "yyyy-MM-dd HH:mm:ss ZZ"
         },
          "last_name": {
            "type": "string"
          }
            }
        }
    }
   

I rather guessed the type mapping as I need something like that desperately. Not sure whether thats correct.

When I post this I am getting the error

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "analyzer on field [myType] must be set when search_analyzer is set"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [type]: analyzer on field [myType] must be set when search_analyzer is set",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "analyzer on field [myType] must be set when search_analyzer is set"
    }
  },
  "status": 400
}

Any clue where I have got it wrong?

UPDATE: My elastic version is 2.2
change from index_analyzer to analyzer gave a different error

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "No handler for type [myType] declared on field [first_name]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [employee]: No handler for type [myType] declared on field [first_name]",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "No handler for type [myType] declared on field [first_name]"
    }
  },
  "status": 400
}

FINAL SOLUTION: Well, my issue was with defining a type. Which I will ignore for the moment but partial search works with following setup

{
"settings" : {
            "analysis" : {
                "analyzer" : {
                    "my_ngram_analyzer" : {
                        "tokenizer" : "my_ngram_tokenizer"
                    }
                },
                "tokenizer" : {
                    "my_ngram_tokenizer" : {
                        "type" : "nGram",
                        "min_gram" : "3",
                        "max_gram" : "12",
                        "token_chars": [ "letter", "digit" ]
                    }
                }
            }
},
 
 "mappings" : {
 
        "employee" : {
            "properties" : {
                      "birth_date": {
                             "type": "date",
                            "format" : "yyyy-MM-dd HH:mm:ss ZZ"
          },
          "emp_no": {
                   "type": "long",
                    "index" : "not_analyzed"
          },
          "first_name": {
            "type": "string",
                        "analyzer" : "my_ngram_analyzer",
                        "search_analyzer" : "my_ngram_analyzer"
          },
          "gender": {
            "type": "string",
              "index" : "not_analyzed"
          },
          "hire_date": { 
                             "type": "date",
                            "format" : "yyyy-MM-dd HH:mm:ss ZZ"
          },
          "last_name": {
            "type": "string",
                        "analyzer" : "my_ngram_analyzer",
                        "search_analyzer" : "my_ngram_analyzer"
          }
            }
        }
    }
}

解决方案

My guess, change index_analyzer with analyzer

  • It's depend your elasticsearch version

EDIT

I'm not familiar with creating type, but you can init first_name with the relevant analyzer:

"first_name": {
  "type" : "string",
  "analyzer" : "translation_index_analyzer",
  "search_analyzer" : "translation_search_analyzer"
},

这篇关于弹性搜索中的部分词搜索的自定义类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆