如何在弹性搜索中给予全文重点? [英] How do I give whole words priority in elasticsearch?

查看:285
本文介绍了如何在弹性搜索中给予全文重点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经尝试了以下内容:

  client.indices.create index:index,
body:{
mappings:{
search_variable:{
属性:{
name=> {
type=> string,
index=> not_analyzed
},
label=> {
type=> string,
index=> not_analyzed
},
value_labels=> {
type=> string,
index=> not_analyzed
},
value_label_search_string=> {
type=> string,
index=> not_analyzed
},
search_text=> {
type=> multi_field,
fields=> {
whole_words=> {type=> string,analyzer=> simple},
ngram=> {type=> string,analyzer=> ngram,search_analyzer=> ngram_search}
}
}
}
},
设置:{
分析:{
过滤器:{
ngram:{
type:'nGram',
min_gram:3,
max_gram:25
}
},
分析器:{
ngram:{
tokenizer:'whitespace',
filter:['smallcase','stop','ngram'],
键入:'custom'
},
ngram_search:{
tokenizer:'whitespace',
filter:['smallcase','stop'],
type: 'custom'
}
}
}
}
}
}

这是与我的全文搜索字段相关的部分: search_text

 search_text=> {
type=> multi_field,
fields=> {
whole_words=> {type=> string,analyzer=> simple},
ngram=> {type=> string,analyzer=> ngram,search_analyzer=> ngram_search}
}
}

我想给更高的分数

  [400] {error:{root_cause:[{类型:mapper_parsing_exception,原因:分析器[ngram_search]找不到字段[ngram]}],类型:mapper_parsing_exception,原因:无法解析映射[search_variable]找不到字段[ngram],due_by:{type:mapper_parsing_exception,reason:analyzer [ngram_search]找不到字段[ngram]}},status:400} 

这是错误:
reason: ngram_search]找不到字段[ngram]



我做错了什么?



编辑:



这是我的查询,我试图在整个单词中匹配现在,我每次只得到0个结果。

  search_query = {
index:index,
body:{
_source:{
exclude:[search_text,survey_id]
},
查询:{
:bool => {
:filter => {
:term => {survey_id=> 12}
},
:must => {
:match => {
search_text.whole_words=> {query=> 宝马,运营商=> and}
}
}
}
}
}
}

result = client.search(search_query)

这是以下输出:
curl -XGET localhost: 9200 / yg_search_variables

  {yg_search_variables:{aliases:{},mappings :{ search_variable:{ 属性:{ 标签:{ 类型: 串, 索引: not_analyzed}, 名称:{ 类型: 串, 索引 : not_analyzed}, SEARCH_TEXT:{ 类型: 串, 索引: 无, 字段:{ 的ngram:{ 类型: 串, 分析器:的ngram  search_analyzer: ngram_search}, whole_words:{ 类型: 串, 分析器: 简单}}}, value_label_search_string:{ 类型: 串,索引 : not_analyzed }, value_labels :{ 类型 : 串, 索引: not_analyzed}}}, 变量:{ 属性:{ 类别:{ 类型 : 串}, 标签:{ 类型: 串, 索引: not_analyzed}, 名称:{ 类型: 串, 索引: not_analyzed}, SEARCH_TEXT:{ 类型: 字符串, 索引: 无}, survey_id:{ 类型: 长}, value_label_search_text:{ 类型: 串}, value_labels:{ 属性: { 0:{ 类型: 串}, 1:{ 类型: 串}, 10:{ 类型: 串}, 100:{型: 串 }, 101 :{ 类型 : 串 }, 102 :{ 类型 : 串 }, 103 :{ 类型 : 串 }, 104 :{ 类型 : 串 }, 105 :{ 类型 : 串 }, 106 :{ 类型 : 串 }, 107 :{ 类型: 串}, 108:{ 类型: 串}, 109:{ 类型: 串}, 11:{ 类型: 串}, 110 :{ 类型: 串}, 1100:{ 类型: 串}, 1101:{ 类型: 串}, 1102:{ 类型:串}, 1103 :{ 类型 : 串 }, 1104 :{ 类型 : 串 }, 1105 :{ 类型 : 串 }, 1106\" :{ 类型: 串}, 1107:{ 类型: 串}, 1108:{ 类型: 串}, 1109:{ 类型: 串} , 111:{ 类型: 串}, 1110:{ 类型: 串}, 1111:{ 类型: 串}, 1112:{型: 串 }, 1113 :{ 类型 : 串 }, 1114 :{ 类型 : 串 }, 112 :{ 类型 : 串 }, 113 :{ 类型 : 串 }, 114 :{ 类型 : 串 }, 115 :{ 类型 : 串 }, 116 :{ 类型: 串},1 17 :{ 类型 : 串 }, 118 :{ 类型 : 串 }, 119 :{ 类型 : 串 }, 12 :{ 类型: 串}, 120:{ 类型: 串}, 121:{ 类型: 串}, 122:{ 类型: 串}, 123 :{ 类型: 串}, 124:{ 类型: 串}, 125:{ 类型: 串}, 126:{ 类型:串}, 127 :{ 类型 : 串 }, 128 :{ 类型 : 串 }, 129 :{ 类型 : 串 }, 13\" :{ 类型: 串}, 130:{ 类型: 串}, 131:{ 类型: 串}, 132:{ 类型: 串} , 133:{ 类型: 串}, 134:{ 类型: 串}, 135:{ 类型: 串}, 136:{型: 串 }, 137 :{ 类型 : 串 }, 138 :{ 类型 : 串 }, 139 :{ 类型 : 串 }, 14 :{ 类型 : 串 }, 140 :{ 类型 : 串 }, 141 :{ 类型 : 串 }, 142 :{ 类型: 串}, 143:{ 类型: 串}, 144:{ 类型: 串}, 145:{ 类型: 串}, 146 :{ 类型: 串}, 147:{ 类型: 串}, 148:{ 类型: 串}, 149:{ 类型:串}, 15 :{ 类型 : 串 }, 150 :{ 类型 : 串 }, 151 :{ 类型 : 串 }, 152\" :{ 类型: 串}, 153:{ 类型: 串}, 154:{ 类型: 串 }, 155:{ 类型: 串}, 156:{ 类型: 串}, 157:{ 类型: 串}, 158:{键入 : 串 }, 159 :{ 类型 : 串 }, 16 :{ 类型 : 串 }, 160 :{ 类型 : 串}, 161:{ 类型: 串}, 162:{ 类型: 串}, 163:{ 类型: 串}, 164:{ 类型 : 串}, 165:{ 类型: 串}, 166:{ 类型: 串}, 167:{ 类型: 串},168 :{ 类型 : 串 }, 169 :{ 类型 : 串 }, 17 :{ 类型 : 串 }, 170 :{ 类型 :串 }, 171 :{ 类型 : 串 }, 172 :{ 类型 : 串 }, 173 :{ 类型 : 串 }, 174\" : { 类型: 串}, 175:{ 类型: 串}, 176:{ 类型: 串}, 177:{ 类型: 串 }, 178:{ 类型: 串}, 179:{ 类型: 串}, 18:{ 类型: 串}, 180:{键入 : 串 }, 181 :{ 类型 : 串 }, 182 :{ 类型 : 串 }, 183 :{ 类型 : 串}, 184:{ 类型: 串}, 185:{ 类型: 串}, 186:{ 类型: 串}, 187:{ 类型 : 串}, 188:{ 类型: 串}, 189:{ 类型: 串}, 19:{ 类型: 串},190 :{ 类型 : 串 }, 191 :{ 类型 : 串 }, 192 :{ 类型 : STR ing 的}, 193 :{ 类型 : 串 }, 194 :{ 类型 : 串 }, 195 :{ 类型 : 串 }, 196\" : { 类型: 串}, 197:{ 类型: 串}, 198:{ 类型: 串}, 199:{ 类型: 串 }, 2:{ 类型: 串}, 20:{ 类型: 串}, 200:{ 类型: 串}, 201:{键入 : 串 }, 202 :{ 类型 : 串 }, 203 :{ 类型 : 串 }, 204​​ :{ 类型 : 串}, 205:{ 类型: 串}, 206:{ 类型: 串}, 207:{ 类型: 串}, 208:{ 类型 : 串}, 209:{ 类型: 串}, 21:{ 类型: 串}, 210:{ 类型: 串},211 :{ 类型 : 串 }, 22 :{ 类型 : 串 }, 23 :{ 类型 : 串 }, 24 :{ 类型 :串 }, 25 :{ 类型 : 串 }, 26 :{ 类型 : 串 }, 27 :{ 类型 : 串 }, 28\" : { 类型: 串}, 29:{ 类型: 串}, 3:{ 类型: 串}, 30:{ 类型: 串 }, 301:{ 类型: 串}, 302:{ 类型: 串}, 303:{ 类型: 串}, 304:{键入 : 串 }, 305 :{ 类型 : 串 }, 306 :{ 类型 : 串 }, 307 :{ 类型 : 串}, 308:{ 类型: 串}, 309:{ 类型: 串}, 31:{ 类型: 串},3 10 :{ 类型 : 串 }, 311 :{ 类型 : 串 }, 312 :{ 类型 : 串 }, 313 :{ 类型: 串}, 314:{ 类型: 串}, 315:{ 类型: 串}, 316:{ 类型: 串}, 317 :{ 类型: 串}, 32:{ 类型: 串}, 33:{ 类型: 串}, 34:{ 类型:串}, 35 :{ 类型 : 串 }, 36 :{ 类型 : 串 }, 37 :{ 类型 : 串 }, 38\" :{ 类型: 串}, 39:{ 类型: 串} 4:{ 类型: 串}, 40:{ 类型: 串} , 41:{ 类型: 串}, 42:{ 类型: 串}, 43:{ 类型: 串}, 44:{型: 串 }, 45 :{ 类型 : 串 }, 46 :{ 类型 : 串 }, 47 :{ 类型 : 串 }, 48 :{ 类型 : 串 }, 49 :{ 类型 : 串 }, 5 :{ 类型 : 串 }, 50 :{ 类型: 串}, 51:{ 类型: 串}, 52:{ 类型: 串}, 53:{ 类型: 串}, 54 :{ 类型: 串}, 55:{ 类型: 串}, 554:{ 类型: 串}, 555:{ 类型:串}, 556 :{ 类型 : 串 }, 56 :{ 类型 : 串 }, 57 :{ 类型 : 串 }, 58\" :{ 类型: 串}, 59:{ 类型: 串}, 6:{ 类型: 串}, 60:{ 类型: 串} , 601 :{ 类型: 串}, 602:{ 类型: 串}, 603:{ 类型: 串}, 604:{ 类型:串}, 61 :{ 类型 : 串 }, 62 :{ 类型 : 串 }, 63 :{ 类型 : 串 }, 64\" :{ 类型: 串}, 65:{ 类型: 串}, 66:{ 类型: 串}, 666:{ 类型: 串} , 667:{ 类型: 串}, 67:{ 类型: 串}, 68:{ 类型: 串}, 69:{型: 串 }, 7 :{ 类型 : 串 }, 70 :{ 类型 : 串 }, 71 :{ 类型 : 串 }, 72 :{ 类型 : 串 }, 73 :{ 类型 : 串 }, 74 :{ 类型 : 串 }, 75 :{ 类型: 串}, 76:{ 类型: 串}, 77:{ 类型: 串}, 777:{ 类型: 串}, 78 :{ 类型: 串}, 79:{ 类型: 串}, 8:{ 类型: 串}, 80:{ 类型:串}, 801 :{ 类型 : 串 }, 802 :{ 类型 : 串 }, 803 :{ 类型 : 串 }, 804\" :{ 类型: 串}, 805:{ 类型: 串}, 806:{ 类型: 串}, 807:{ 类型: 串} , 808:{ 类型: 串}, 809:{ 类型: 串}, 81:{ 类型: 串}, 810:{型: 串 }, 811 :{ 类型 : 串 }, 812 :{ 类型 : 串 }, 813 :{ 类型 : 串 }, 814:{ 类型: 串}, 815:{ 类型: 串}, 816:{ 类型: 串}, 817:{键入 : 串 }, 818 :{ 类型 : 串 }, 819 :{ 类型 : 串 }, 82 :{ 类型 : 串}, 820:{ 类型: 串}, 821:{ 类型: 串}, 822:{ 类型: 串}, 83:{ 类型 : 串}, 84:{ 类型: 串}, 85:{ 类型: 串}, 86:{ 类型: 串},87 :{ 类型 : 串 }, 88 :{ 类型 : 串 }, 888 :{ 类型 : 串 }, 89 :{ 类型 :字符串 }, 9 :{ 类型 : 串 }, 90 :{ 类型 : 串 }, 901 :{ 类型 : 串 }, 902\" : { 类型: 串}, 903:{ 类型: 串}, 904:{ 类型: 串}, 905:{ 类型: 串 }, 906:{ 类型: 串}, 907:{ 类型: 串}, 908:{ 类型: 串}, 909:{键入 : 串 }, 91 :{ 类型 : 串 }, 910 :{ 类型 : 串 }, 911 :{ 类型 : 串}, 912:{ 类型: 串}, 913:{ 类型: 串}, 914:{ 类型: 串}, 915:{ 类型 : 串}, 916:{ 类型: 串}, 917:{ 类型: 串}, 918:{ 类型: 串},919 :{ 类型 : 串 }, 92 :{ 类型 : 串 }, 920 :{ 类型 : 串 }, 92 1 :{ 类型 : 串 }, 922 :{ 类型 : 串 }, 923 :{ 类型 : 串 }, 924 :{ 类型: 串}, 925:{ 类型: 串}, 926:{ 类型: 串}, 927:{ 类型: 串}, 928 :{ 类型: 串}, 93:{ 类型: 串}, 94:{ 类型: 串}, 95:{ 类型:串}, 96 :{ 类型 : 串 }, 97 :{ 类型 : 串 }, 98 :{ 类型 : 串 }, 99\" :{ 类型: 串}, 997:{ 类型: 串}, 998:{ 类型: 串}, 999:{ 类型: 串} }}}}}, 设置:{ 索引:{ CREATION_DATE: 1457103857764, 分析:{ 过滤器:{ 的ngram:{ 类型: 的ngram, min_gram : 3, max_gram: 25}}, 分析器:{ 的ngram:{ 过滤器:[ 小写, 停止, 的ngram], 类型: 定制 标记生成器: 空白}, ngram_search:{ 过滤器:[ 小写, 停止], 类型: 定制, 标记者: 空白}}},number_of_shards :5,number_of_replicas:1,uuid:zPN2LDfCTFqPleW7d5nkwA,version:{created:2020099}}},warmers:{}}}%

索引是 no 似乎很奇怪:

 searc h_text:{
type:string,
index:no,
fields:{
ngram:{
type:string,
analyzer:ngram,
search_analyzer:ngram_search
},
full_words:{
type:string,
analyzer:simple
}
}
}

编辑:以下是福特一词的匹配文档示例:

  {
name=>car_ownership,
label=>客户:福特,
category=> [车辆车辆],值=> nil,
value_labels=> {1=>是,2=>否},
node_id => 14813,
survey_id=> 12,
search_text=> 客户福特车辆乘用车是否
}

编辑:我添加了一个较小的开始结束可以在这里找到的测试用例,复制错误。



https://www.dropbox.com/s/wwxm3qe0oxc2z5y/Slimmed%20ElasticSearch%20Text%20%281%29。 html?dl = 0

解决方案

第一个问题是设置未正确嵌套。 设置映射应在同一级别。



然后,看看你的收件箱文件,我认为问题是映射类型称为 search_variable 而在批量中你使用映射类型 test_type 。因此,映射将永远不会被应用。


Elasticsearch is running well for me at the moment, however I want to give whole words priority over Ngrams.

I've tried the following:

client.indices.create index: index,
                      body: {
                          mappings: {
                              search_variable: {
                                  properties: {
                                      "name" => {
                                          "type" => "string",
                                          "index" => "not_analyzed"
                                      },
                                      "label" => {
                                          "type" => "string",
                                          "index" => "not_analyzed"
                                      },
                                      "value_labels" => {
                                          "type" => "string",
                                          "index" => "not_analyzed"
                                      },
                                      "value_label_search_string" => {
                                          "type" => "string",
                                          "index" => "not_analyzed"
                                      },
                                      "search_text" => {
                                          "type" => "multi_field",
                                          "fields" => {
                                            "whole_words" => {"type" => "string", "analyzer" => "simple"},
                                            "ngram" => {"type" => "string", "analyzer" => "ngram", "search_analyzer" => "ngram_search"}
                                          }
                                      }
                                  }
                              },
                              settings: {
                                  analysis: {
                                      filter: {
                                          ngram: {
                                              type: 'nGram',
                                              min_gram: 3,
                                              max_gram: 25
                                          }
                                      },
                                      analyzer: {
                                          ngram: {
                                              tokenizer: 'whitespace',
                                              filter: ['lowercase', 'stop', 'ngram'],
                                              type: 'custom'
                                          },
                                          ngram_search: {
                                              tokenizer: 'whitespace',
                                              filter: ['lowercase', 'stop'],
                                              type: 'custom'
                                          }
                                      }
                                  }
                              }
                          }   
                      } 

This is the part relevant to my full text search field: search_text:

"search_text" => {
    "type" => "multi_field",
    "fields" => {
        "whole_words" => {"type" => "string", "analyzer" => "simple"},
        "ngram" => {"type" => "string", "analyzer" => "ngram", "search_analyzer" => "ngram_search"}
    }
}

I want to give higher scores to items that match whole words in the search text.

[400] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"analyzer [ngram_search] not found for field [ngram]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [search_variable]: analyzer [ngram_search] not found for field [ngram]","caused_by":{"type":"mapper_parsing_exception","reason":"analyzer [ngram_search] not found for field [ngram]"}},"status":400}

Here's the error: "reason":"analyzer [ngram_search] not found for field [ngram]"

What am I doing wrong?

Edit:

Here is my query, where I tried to match on whole words only for now, and I only get 0 results every time.

    search_query = {
        index: index,
        body: {
            _source: {
                exclude: ["search_text", "survey_id"]
            },
            query: {
                :bool => {
                    :filter => {
                        :term => {"survey_id" => 12}
                    },
                    :must => {
                        :match => {
                          "search_text.whole_words" => {"query" => "BMW", "operator" => "and"}
                        }
                    }
                }
            }
        }
    }

    result = client.search(search_query)

Here is the output of: curl -XGET localhost:9200/yg_search_variables

{"yg_search_variables":{"aliases":{},"mappings":{"search_variable":{"properties":{"label":{"type":"string","index":"not_analyzed"},"name":{"type":"string","index":"not_analyzed"},"search_text":{"type":"string","index":"no","fields":{"ngram":{"type":"string","analyzer":"ngram","search_analyzer":"ngram_search"},"whole_words":{"type":"string","analyzer":"simple"}}},"value_label_search_string":{"type":"string","index":"not_analyzed"},"value_labels":{"type":"string","index":"not_analyzed"}}},"variables":{"properties":{"category":{"type":"string"},"label":{"type":"string","index":"not_analyzed"},"name":{"type":"string","index":"not_analyzed"},"search_text":{"type":"string","index":"no"},"survey_id":{"type":"long"},"value_label_search_text":{"type":"string"},"value_labels":{"properties":{"0":{"type":"string"},"1":{"type":"string"},"10":{"type":"string"},"100":{"type":"string"},"101":{"type":"string"},"102":{"type":"string"},"103":{"type":"string"},"104":{"type":"string"},"105":{"type":"string"},"106":{"type":"string"},"107":{"type":"string"},"108":{"type":"string"},"109":{"type":"string"},"11":{"type":"string"},"110":{"type":"string"},"1100":{"type":"string"},"1101":{"type":"string"},"1102":{"type":"string"},"1103":{"type":"string"},"1104":{"type":"string"},"1105":{"type":"string"},"1106":{"type":"string"},"1107":{"type":"string"},"1108":{"type":"string"},"1109":{"type":"string"},"111":{"type":"string"},"1110":{"type":"string"},"1111":{"type":"string"},"1112":{"type":"string"},"1113":{"type":"string"},"1114":{"type":"string"},"112":{"type":"string"},"113":{"type":"string"},"114":{"type":"string"},"115":{"type":"string"},"116":{"type":"string"},"117":{"type":"string"},"118":{"type":"string"},"119":{"type":"string"},"12":{"type":"string"},"120":{"type":"string"},"121":{"type":"string"},"122":{"type":"string"},"123":{"type":"string"},"124":{"type":"string"},"125":{"type":"string"},"126":{"type":"string"},"127":{"type":"string"},"128":{"type":"string"},"129":{"type":"string"},"13":{"type":"string"},"130":{"type":"string"},"131":{"type":"string"},"132":{"type":"string"},"133":{"type":"string"},"134":{"type":"string"},"135":{"type":"string"},"136":{"type":"string"},"137":{"type":"string"},"138":{"type":"string"},"139":{"type":"string"},"14":{"type":"string"},"140":{"type":"string"},"141":{"type":"string"},"142":{"type":"string"},"143":{"type":"string"},"144":{"type":"string"},"145":{"type":"string"},"146":{"type":"string"},"147":{"type":"string"},"148":{"type":"string"},"149":{"type":"string"},"15":{"type":"string"},"150":{"type":"string"},"151":{"type":"string"},"152":{"type":"string"},"153":{"type":"string"},"154":{"type":"string"},"155":{"type":"string"},"156":{"type":"string"},"157":{"type":"string"},"158":{"type":"string"},"159":{"type":"string"},"16":{"type":"string"},"160":{"type":"string"},"161":{"type":"string"},"162":{"type":"string"},"163":{"type":"string"},"164":{"type":"string"},"165":{"type":"string"},"166":{"type":"string"},"167":{"type":"string"},"168":{"type":"string"},"169":{"type":"string"},"17":{"type":"string"},"170":{"type":"string"},"171":{"type":"string"},"172":{"type":"string"},"173":{"type":"string"},"174":{"type":"string"},"175":{"type":"string"},"176":{"type":"string"},"177":{"type":"string"},"178":{"type":"string"},"179":{"type":"string"},"18":{"type":"string"},"180":{"type":"string"},"181":{"type":"string"},"182":{"type":"string"},"183":{"type":"string"},"184":{"type":"string"},"185":{"type":"string"},"186":{"type":"string"},"187":{"type":"string"},"188":{"type":"string"},"189":{"type":"string"},"19":{"type":"string"},"190":{"type":"string"},"191":{"type":"string"},"192":{"type":"string"},"193":{"type":"string"},"194":{"type":"string"},"195":{"type":"string"},"196":{"type":"string"},"197":{"type":"string"},"198":{"type":"string"},"199":{"type":"string"},"2":{"type":"string"},"20":{"type":"string"},"200":{"type":"string"},"201":{"type":"string"},"202":{"type":"string"},"203":{"type":"string"},"204":{"type":"string"},"205":{"type":"string"},"206":{"type":"string"},"207":{"type":"string"},"208":{"type":"string"},"209":{"type":"string"},"21":{"type":"string"},"210":{"type":"string"},"211":{"type":"string"},"22":{"type":"string"},"23":{"type":"string"},"24":{"type":"string"},"25":{"type":"string"},"26":{"type":"string"},"27":{"type":"string"},"28":{"type":"string"},"29":{"type":"string"},"3":{"type":"string"},"30":{"type":"string"},"301":{"type":"string"},"302":{"type":"string"},"303":{"type":"string"},"304":{"type":"string"},"305":{"type":"string"},"306":{"type":"string"},"307":{"type":"string"},"308":{"type":"string"},"309":{"type":"string"},"31":{"type":"string"},"310":{"type":"string"},"311":{"type":"string"},"312":{"type":"string"},"313":{"type":"string"},"314":{"type":"string"},"315":{"type":"string"},"316":{"type":"string"},"317":{"type":"string"},"32":{"type":"string"},"33":{"type":"string"},"34":{"type":"string"},"35":{"type":"string"},"36":{"type":"string"},"37":{"type":"string"},"38":{"type":"string"},"39":{"type":"string"},"4":{"type":"string"},"40":{"type":"string"},"41":{"type":"string"},"42":{"type":"string"},"43":{"type":"string"},"44":{"type":"string"},"45":{"type":"string"},"46":{"type":"string"},"47":{"type":"string"},"48":{"type":"string"},"49":{"type":"string"},"5":{"type":"string"},"50":{"type":"string"},"51":{"type":"string"},"52":{"type":"string"},"53":{"type":"string"},"54":{"type":"string"},"55":{"type":"string"},"554":{"type":"string"},"555":{"type":"string"},"556":{"type":"string"},"56":{"type":"string"},"57":{"type":"string"},"58":{"type":"string"},"59":{"type":"string"},"6":{"type":"string"},"60":{"type":"string"},"601":{"type":"string"},"602":{"type":"string"},"603":{"type":"string"},"604":{"type":"string"},"61":{"type":"string"},"62":{"type":"string"},"63":{"type":"string"},"64":{"type":"string"},"65":{"type":"string"},"66":{"type":"string"},"666":{"type":"string"},"667":{"type":"string"},"67":{"type":"string"},"68":{"type":"string"},"69":{"type":"string"},"7":{"type":"string"},"70":{"type":"string"},"71":{"type":"string"},"72":{"type":"string"},"73":{"type":"string"},"74":{"type":"string"},"75":{"type":"string"},"76":{"type":"string"},"77":{"type":"string"},"777":{"type":"string"},"78":{"type":"string"},"79":{"type":"string"},"8":{"type":"string"},"80":{"type":"string"},"801":{"type":"string"},"802":{"type":"string"},"803":{"type":"string"},"804":{"type":"string"},"805":{"type":"string"},"806":{"type":"string"},"807":{"type":"string"},"808":{"type":"string"},"809":{"type":"string"},"81":{"type":"string"},"810":{"type":"string"},"811":{"type":"string"},"812":{"type":"string"},"813":{"type":"string"},"814":{"type":"string"},"815":{"type":"string"},"816":{"type":"string"},"817":{"type":"string"},"818":{"type":"string"},"819":{"type":"string"},"82":{"type":"string"},"820":{"type":"string"},"821":{"type":"string"},"822":{"type":"string"},"83":{"type":"string"},"84":{"type":"string"},"85":{"type":"string"},"86":{"type":"string"},"87":{"type":"string"},"88":{"type":"string"},"888":{"type":"string"},"89":{"type":"string"},"9":{"type":"string"},"90":{"type":"string"},"901":{"type":"string"},"902":{"type":"string"},"903":{"type":"string"},"904":{"type":"string"},"905":{"type":"string"},"906":{"type":"string"},"907":{"type":"string"},"908":{"type":"string"},"909":{"type":"string"},"91":{"type":"string"},"910":{"type":"string"},"911":{"type":"string"},"912":{"type":"string"},"913":{"type":"string"},"914":{"type":"string"},"915":{"type":"string"},"916":{"type":"string"},"917":{"type":"string"},"918":{"type":"string"},"919":{"type":"string"},"92":{"type":"string"},"920":{"type":"string"},"921":{"type":"string"},"922":{"type":"string"},"923":{"type":"string"},"924":{"type":"string"},"925":{"type":"string"},"926":{"type":"string"},"927":{"type":"string"},"928":{"type":"string"},"93":{"type":"string"},"94":{"type":"string"},"95":{"type":"string"},"96":{"type":"string"},"97":{"type":"string"},"98":{"type":"string"},"99":{"type":"string"},"997":{"type":"string"},"998":{"type":"string"},"999":{"type":"string"}}}}}},"settings":{"index":{"creation_date":"1457103857764","analysis":{"filter":{"ngram":{"type":"nGram","min_gram":"3","max_gram":"25"}},"analyzer":{"ngram":{"filter":["lowercase","stop","ngram"],"type":"custom","tokenizer":"whitespace"},"ngram_search":{"filter":["lowercase","stop"],"type":"custom","tokenizer":"whitespace"}}},"number_of_shards":"5","number_of_replicas":"1","uuid":"zPN2LDfCTFqPleW7d5nkwA","version":{"created":"2020099"}}},"warmers":{}}}%

It seems strange that index is no:

     "search_text": {
        "type": "string",
        "index": "no",
        "fields": {
          "ngram": {
            "type": "string",
            "analyzer": "ngram",
            "search_analyzer": "ngram_search"
          },
          "whole_words": {
            "type": "string",
            "analyzer": "simple"
          }
        }
      }

Edit: Here is a sample matching document for the term "Ford":

{
  "name"=>"car_ownership", 
  "label"=>"Customer: Ford", 
  "category"=>["Vehicles", "Passenger Vehicles"], "value"=>nil, 
  "value_labels"=>{"1"=>"Yes", "2"=>"No"}, 
  "node_id"=>14813, 
  "survey_id" => 12,
  "search_text" => "Customer Ford Vehicles Passenger Vehicles Yes No"
}

Edit: I have added a smaller beginning to end test case that can be found here, which replicates the error.

https://www.dropbox.com/s/wwxm3qe0oxc2z5y/Slimmed%20ElasticSearch%20Text%20%281%29.html?dl=0

解决方案

The first issue is that settings is not properly nested when you create your index. settings and mappings should be at the same level.

Then, looking at your dropbox file, I think the issue is that the mapping type is called search_variable while in your bulk you are using the mapping type test_type. Hence the mapping will never be applied.

这篇关于如何在弹性搜索中给予全文重点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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