analyzer
编辑analyzer
编辑只有 text
字段支持 analyzer
映射参数。
analyzer
参数指定在索引或搜索 text
字段时用于 文本分析 的 分析器。
除非被 search_analyzer
映射参数覆盖,否则此分析器将用于 索引和搜索分析。请参阅 指定分析器。
我们建议在生产环境中使用分析器之前进行测试。请参阅 测试分析器。
analyzer
设置不能使用更新映射 API在现有字段上更新。
search_quote_analyzer
编辑search_quote_analyzer
设置允许您为短语指定分析器,这在处理禁用短语查询的停用词时特别有用。
要为短语禁用停用词,需要一个字段使用三个分析器设置
- 一个
analyzer
设置,用于索引所有词项,包括停用词 - 一个
search_analyzer
设置,用于删除停用词的非短语查询 - 一个
search_quote_analyzer
设置,用于不删除停用词的短语查询
resp = client.indices.create( index="my-index-000001", settings={ "analysis": { "analyzer": { "my_analyzer": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase" ] }, "my_stop_analyzer": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "english_stop" ] } }, "filter": { "english_stop": { "type": "stop", "stopwords": "_english_" } } } }, mappings={ "properties": { "title": { "type": "text", "analyzer": "my_analyzer", "search_analyzer": "my_stop_analyzer", "search_quote_analyzer": "my_analyzer" } } }, ) print(resp) resp1 = client.index( index="my-index-000001", id="1", document={ "title": "The Quick Brown Fox" }, ) print(resp1) resp2 = client.index( index="my-index-000001", id="2", document={ "title": "A Quick Brown Fox" }, ) print(resp2) resp3 = client.search( index="my-index-000001", query={ "query_string": { "query": "\"the quick brown fox\"" } }, ) print(resp3)
response = client.indices.create( index: 'my-index-000001', body: { settings: { analysis: { analyzer: { my_analyzer: { type: 'custom', tokenizer: 'standard', filter: [ 'lowercase' ] }, my_stop_analyzer: { type: 'custom', tokenizer: 'standard', filter: [ 'lowercase', 'english_stop' ] } }, filter: { english_stop: { type: 'stop', stopwords: '_english_' } } } }, mappings: { properties: { title: { type: 'text', analyzer: 'my_analyzer', search_analyzer: 'my_stop_analyzer', search_quote_analyzer: 'my_analyzer' } } } } ) puts response response = client.index( index: 'my-index-000001', id: 1, body: { title: 'The Quick Brown Fox' } ) puts response response = client.index( index: 'my-index-000001', id: 2, body: { title: 'A Quick Brown Fox' } ) puts response response = client.search( index: 'my-index-000001', body: { query: { query_string: { query: '"the quick brown fox"' } } } ) puts response
const response = await client.indices.create({ index: "my-index-000001", settings: { analysis: { analyzer: { my_analyzer: { type: "custom", tokenizer: "standard", filter: ["lowercase"], }, my_stop_analyzer: { type: "custom", tokenizer: "standard", filter: ["lowercase", "english_stop"], }, }, filter: { english_stop: { type: "stop", stopwords: "_english_", }, }, }, }, mappings: { properties: { title: { type: "text", analyzer: "my_analyzer", search_analyzer: "my_stop_analyzer", search_quote_analyzer: "my_analyzer", }, }, }, }); console.log(response); const response1 = await client.index({ index: "my-index-000001", id: 1, document: { title: "The Quick Brown Fox", }, }); console.log(response1); const response2 = await client.index({ index: "my-index-000001", id: 2, document: { title: "A Quick Brown Fox", }, }); console.log(response2); const response3 = await client.search({ index: "my-index-000001", query: { query_string: { query: '"the quick brown fox"', }, }, }); console.log(response3);
PUT my-index-000001 { "settings":{ "analysis":{ "analyzer":{ "my_analyzer":{ "type":"custom", "tokenizer":"standard", "filter":[ "lowercase" ] }, "my_stop_analyzer":{ "type":"custom", "tokenizer":"standard", "filter":[ "lowercase", "english_stop" ] } }, "filter":{ "english_stop":{ "type":"stop", "stopwords":"_english_" } } } }, "mappings":{ "properties":{ "title": { "type":"text", "analyzer":"my_analyzer", "search_analyzer":"my_stop_analyzer", "search_quote_analyzer":"my_analyzer" } } } } PUT my-index-000001/_doc/1 { "title":"The Quick Brown Fox" } PUT my-index-000001/_doc/2 { "title":"A Quick Brown Fox" } GET my-index-000001/_search { "query":{ "query_string":{ "query":"\"the quick brown fox\"" } } }
search_quote_analyzer
设置可以使用更新映射 API在现有字段上更新。
|
|
|
|
|
|
|
|
|
|
由于查询被引号包裹,因此它被检测为短语查询,因此 |