I have configured the my index with the following settings and the matchAll query results the have a value "trial" in the field IPRANGE.
The settings:
{
"settings" : {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 5
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings" : {
"users" : {
"properties" : {
"IPRANGE" : {
"type" : "string",
"analyzer" : "autocomplete"
}
}
}
},
refresh_interval: "1000"
}
But when I search with following payload it doesn't return results, ie is 0 hits.
URL:
http://xxxxxx:9200/db2/users/_search
Payload:
{
"query": {
"match": {
"IPRANGE": "tr"
}
}
}
What could be the issue?
How have you indexed the document? Here is an example that works:
I changed the mapping so that the autocomplete
analyzer is used to index the IPRANGE
field, when searching against the field the default analyzer will be used (you don't want to split the search term in same way).
/POST http://localhost:9200/test
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 5
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"users": {
"properties": {
"IPRANGE": {
"type": "string",
"search_analyzer": "autocomplete"
}
}
}
}
}
Index the document
/POST http://localhost:9200/test/users/1/
{
"IPRANGE":"trial"
}
Search request:
/POST http://localhost:9200/test/users/_search
{
"query": {
"match": {
"IPRANGE": "tr"
}
}
}
Returns the following result:
{
took: 10
timed_out: false
_shards: {
total: 5
successful: 5
failed: 0
}
hits: {
total: 1
max_score: 0.30685282
hits: [
{
_index: test
_type: users
_id: 1
_score: 0.30685282
_source: {
IPRANGE: trial
}
}
]
}
}