Continuing the discussion from Exact match not working:
printf "\nDelete the index to start from scratch\n";
curl -XDELETE 'http://192.168.134.179:9200/testnames2'
printf "\nCreate the index with a single type, and one field which is not_analyzed\n";
curl -XPOST http://192.168.134.179:9200/testnames2 -d '{
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"hrname" : {
"_all" : { "enabled" : false },
"properties" : {
"rawLookup" : { "type" : "string", "index" : "not_analyzed" }
}
}
}
}'
printf "\nCheck mappings have persisted\n";
curl -XGET 'http://192.168.134.179:9200/testnames2/_mappings/?pretty=true'
printf "\nAdd one record into the index of the right type\n";
curl -XPUT 'http://192.168.134.179:9200/testnames2/hrname/1' -d '{
"rawLookup" : "Simon Taylor"
}'
printf "\nRefresh index\n";
curl -XPOST 'http://192.168.134.179:9200/testnames2/_refresh'
printf "\nAttempt to get the field back using a filtered query using one term with the exact text i inputted\n";
curl -XGET 'http://192.168.134.179:9200/testnames2/_search/?pretty=true' -d '
{
"query" : {
"filtered" : {
"filter" : {
"term" : {
"rawLookup" : "Simon Taylor"
}
}
}
}
}
'
printf "Now just using Query Term RawLookup\n";
curl -XGET 'http://192.168.134.179:9200/testnames2/_search/?pretty=true' -d '
{
"query" : {
"term" : {
"rawLookup" : "Simon Taylor"
}
}
}
'
printf "Output of analyze"
curl -XGET http://192.168.134.179:9200/testnames2/_analyze?pretty=1,field=rawLookup -d'
Simon Taylor'
Generates this:-
Delete the index to start from scratch
{"acknowledged":true}
Create the index with a single type, and one field which is not_analyzed
{"acknowledged":true}
Check mappings have persisted
{
"testnames2" : {
"mappings" : {
"hrname" : {
"_all" : {
"enabled" : false
},
"properties" : {
"rawLookup" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
}
}
Add one record into the index of the right type
{"_index":"testnames2","_type":"hrname","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}
Refresh index
{"_shards":{"total":2,"successful":1,"failed":0}}
Attempt to get the field back using a filtered query using one term with the exact text i inputted
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "testnames2",
"_type" : "hrname",
"_id" : "1",
"_score" : 1.0,
"_source":{
"rawLookup" : "Simon Taylor"
}
} ]
}
}
Now just using Query Term RawLookup
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.30685282,
"hits" : [ {
"_index" : "testnames2",
"_type" : "hrname",
"_id" : "1",
"_score" : 0.30685282,
"_source":{
"rawLookup" : "Simon Taylor"
}
} ]
}
}
Output of analyze{
"tokens" : [ {
"token" : "simon",
"start_offset" : 1,
"end_offset" : 6,
"type" : "<ALPHANUM>",
"position" : 0
}, {
"token" : "taylor",
"start_offset" : 7,
"end_offset" : 13,
"type" : "<ALPHANUM>",
"position" : 1
} ]
}
Simons-MacBook-Pro:elastic simon$