-
-
Save edwinf/d422f0e66a0022173b44 to your computer and use it in GitHub Desktop.
Not Analyzed field not returning exact match. I'm doing something wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
curl -XDELETE "http://localhost:9200/docs" | |
curl -XPOST "http://localhost:9200/docs" -d ' | |
{ | |
"settings": { | |
"index": { | |
"number_of_replicas": 1, | |
"number_of_shards": 5, | |
"analysis": { | |
"analyzer": { | |
"default": { | |
"tokenizer": "standard", | |
"filter": ["standard", | |
"lowercase", | |
"stop", | |
"snowballfilter"], | |
"type": "custom" | |
}, | |
"simple": { | |
"type": "simple" | |
}, | |
"autocomplete": { | |
"tokenizer": "standard", | |
"filter": ["standard", | |
"lowercase", | |
"stop", | |
"kstem", | |
"ngram"], | |
"type": "custom" | |
} | |
}, | |
"filter": { | |
"ngram": { | |
"min_gram": 2, | |
"max_gram": 10, | |
"type": "nGram" | |
}, | |
"snowballfilter": { | |
"language": "English", | |
"type": "snowball" | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
curl -XPOST "http://localhost:9200/docs/document/_mapping" -d ' | |
{ | |
"document": { | |
"_id": { | |
"path": "titleID", | |
"index": "analyzed" | |
}, | |
"properties": { | |
"documentCreator": { | |
"type": "multi_field", | |
"fields": { | |
"documentCreator": { | |
"type": "string", | |
"index": "not_analyzed" | |
}, | |
"documentCreator.stemmed": { | |
"type": "string" | |
} | |
} | |
}, | |
"title": { | |
"type": "multi_field", | |
"fields": { | |
"title": { | |
"type": "string", | |
"index": "not_analyzed" | |
}, | |
"title.stemmed": { | |
"type": "string" | |
}, | |
"title.autocomplete": { | |
"type": "string", | |
"index_analyzer": "autocomplete" | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
curl -XPOST "http://localhost:9200/docs/document" -d ' | |
{ | |
documentCreator: ["Bob Smith","Jane Doe","John Doe"], | |
title: "A Random Document Title", | |
titleID: 1 | |
} | |
' | |
curl -XPOST "http://localhost:9200/docs/_refresh" | |
#to demonostrate the facet results, for why I did a not analyzed field for name. | |
curl -XPOST "http://localhost:9200/docs/document/_search" -d ' | |
{ | |
"from": 0, | |
"size": 48, | |
"facets": { | |
"documentCreator": { | |
"terms": { | |
"field": "documentCreator", | |
"size": 20 | |
} | |
} | |
}, | |
"query": { | |
"query_string": { | |
"query": "Bob Smith", | |
"fields": [ | |
"documentCreator^3", | |
"title^1.5", | |
"documentCreator.stemmed" | |
] | |
} | |
}, | |
"filter": { | |
"match_all": {} | |
} | |
} | |
' | |
#Requirement to boost exact match higher to bring forward those that know exactly what they're looking for. Doesn't match on anything with a space in it (which is pretty much every proper name) | |
curl -XPOST "http://localhost:9200/docs/document/_search" -d ' | |
{ | |
"from": 0, | |
"size": 48, | |
"facets": { | |
"documentCreator": { | |
"terms": { | |
"field": "documentCreator", | |
"size": 20 | |
} | |
} | |
}, | |
"query": { | |
"query_string": { | |
"query": "Bob Smith", | |
"fields": [ | |
"documentCreator^3", | |
"title^1.5" | |
] | |
} | |
}, | |
"filter": { | |
"match_all": {} | |
} | |
} | |
' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The second search has the stemmed field removed to show that it is not returning any results based on the not_analyzed field.