Skip to content

Instantly share code, notes, and snippets.

@alexbrasetvik
Created January 16, 2014 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexbrasetvik/3e5fcb1b4c41cfc20226 to your computer and use it in GitHub Desktop.
Save alexbrasetvik/3e5fcb1b4c41cfc20226 to your computer and use it in GitHub Desktop.
text:
- SVF-123
- SVF-234
analyzer:
analyzer_keyword:
type: custom
tokenizer: keyword
filter:
- lowercase
name: "SVF-123"
---
name: "SVF-234"
type:
# Your query_string query ends up as an OR on "*svf" and "1*".
# _all:
# enabled: false
properties:
name:
type: string
# This is problematic. Terms are not being analyzed index time,
# but is search time. And the search time analyzer generates incompatible terms.
index: not_analyzed
analyzer: analyzer_keyword
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"settings": {
"analysis": {
"text": [
"SVF-123",
"SVF-234"
],
"analyzer": {
"analyzer_keyword": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"type": {
"properties": {
"name": {
"type": "string",
"index": "not_analyzed",
"analyzer": "analyzer_keyword"
}
}
}
}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type"}}
{"name":"SVF-123"}
{"index":{"_index":"play","_type":"type"}}
{"name":"SVF-234"}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"facets": {
"name": {
"terms": {
"field": "name"
}
},
"_all": {
"terms": {
"field": "_all"
}
}
}
}
'
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"match": {
"name": {
"query": "SVF-123"
}
}
}
}
'
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"term": {
"name": {
"value": "SVF-123"
}
}
}
}
'
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"term": {
"_all": {
"value": "svf"
}
}
}
}
'
# Auto generated by Found's Play-tool at 2014-01-16T15:12:43+01:00
version: 0
title: "Erroneous analysis configuration "
description: ""
# In reply to http://stackoverflow.com/questions/21161062/elasticsearch-wildcard-search-on-not-analyzed-field
# See all the generated terms.
facets:
name:
terms:
field: name
_all:
terms:
field: _all
---
query:
match:
name:
# Analyzed, so no match
query: "SVF-123"
---
query:
term:
name:
# Not analyzed according to `analyzer_keyword`, so matches.
value: "SVF-123"
---
query:
term:
_all:
value: svf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment