analyzer
analyzer
Only text fields support the analyzer
mapping parameter.
The analyzer
parameter specifies the analyzer used for text analysis when indexing or searching a text
field.
Unless overridden with the search_analyzer mapping parameter, this analyzer is used for both index and search analysis. See Specify an analyzer.
We recommend testing analyzers before using them in production. See Test an analyzer.
The analyzer
setting can not be updated on existing fields using the update mapping API.
search_quote_analyzer
The search_quote_analyzer
setting allows you to specify an analyzer for phrases, this is particularly useful when dealing with disabling stop words for phrase queries.
To disable stop words for phrases a field utilising three analyzer settings will be required:
- An
analyzer
setting for indexing all terms including stop words - A
search_analyzer
setting for non-phrase queries that will remove stop words - A
search_quote_analyzer
setting for phrase queries that will not remove stop words
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\""
}
}
}
The search_quote_analyzer
setting can be updated on existing fields using the update mapping API.
| |
| |
| |
| |
| |
Since the query is wrapped in quotes it is detected as a phrase query therefore the |