Hi,
I am not sure where the exact problem is, maybe it is related to the mapping that is created for you. You can check the mapping with:
GET /fuelrats/_mapping
(where "fuelrats" is the index name)
Here is a pure Elasticsearch example that you can paste directly into Sense and play around there:
We first create the index. I have not included all properties that you use though:
PUT /fuelrats
{
"mappings": {
"rat": {
"properties": {
"archive": {
"type": "boolean"
},
"CMDRname": {
type: "string"
}
}
}
}
}
Then we index a few documents:
POST /_bulk
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Crazy","archive":false}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Trezy","archive":true}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Tracy","archive":true}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Tracey","archive":true}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Trezi","archive":true}
{"index":{"_index":"fuelrats","_type":"rat"}}
{"CMDRname":"Trazy","archive":true}
And fuzzy-search for them:
GET /_search
{
"query": {
"filtered": {
"query": {
"fuzzy": {
"CMDRname": {
"term": "Trezy",
"fuzziness": "auto"
}
}
},
"filter": {
"term": {
"archive": true
}
}
}
}
}
This returns one hit; the document with CMDRname "Trezy". Note that fuzzy queries do not run through the analyzer. This is how Elasticsearch sees the "CMDRname" property of a "rat" document:
GET /fuelrats/_analyze
{
"field": "CMDRname",
"text": "Trezi"
}
this produces:
{
"tokens": [
{
"token": "trezi",
"start_offset": 0,
"end_offset": 5,
"type": "<ALPHANUM>",
"position": 0
}
]
}
So, the standard analyzer that is used for analyzing the text produces "trezi". But a fuzzy query will not run through this analysis stage and will internally try to fuzzy-match "Trezi" against "trezi". As the field "CMDRname" seems to be some kind of username you probably want to set index to "not_analyzed" anyway (see docs on index mapping options).
By the way, the filtered query is deprecated starting from Elasticsearch 2.0 (see also https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html). You should use a bool query instead:
GET /_search
{
"query": {
"bool": {
"must": {
"fuzzy": {
"CMDRname": {
"term": "Trezy",
"fuzziness": "auto"
}
}
},
"filter": {
"term": {
"archive": true
}
}
}
}
}
I hope that solves your problem.
Daniel