Created
November 24, 2013 17:00
-
-
Save alexbrasetvik/7629456 to your computer and use it in GitHub Desktop.
Demo that "prefix"-query does not analyze the query text.
This file contains hidden or 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
analyzer: | |
sample: | |
text: | |
- Jon Snow | |
- Big Ben | |
tokenizer: standard | |
type: custom | |
filter: | |
- lowercase | |
This file contains hidden or 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
--- | |
_id: 1 | |
color: green | |
driver: | |
born: "1989-09-12" | |
name: Ben | |
make: BMW | |
model: Aztek | |
value: 3000 | |
year: 2003 | |
--- | |
_id: 2 | |
color: black | |
driver: | |
born: "1934-09-08" | |
name: Jon | |
make: Mercedes | |
model: Benz | |
value: 10000 | |
year: 2012 | |
--- | |
_id: 3 | |
color: green | |
driver: | |
born: "1934-09-08" | |
name: Jon | |
make: BMW | |
model: Benz | |
value: 10000 | |
year: 2012 |
This file contains hidden or 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/bash | |
export ELASTICSEARCH_ENDPOINT="http://localhost:9200" | |
# Create indexes | |
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{ | |
"settings": { | |
"analysis": { | |
"analyzer": { | |
"sample": { | |
"tokenizer": "standard", | |
"type": "custom", | |
"filter": [ | |
"lowercase" | |
] | |
} | |
} | |
} | |
} | |
}' | |
# Index documents | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d ' | |
{"index":{"_index":"play","_type":"type","_id":1}} | |
{"color":"green","driver":{"born":"1989-09-12","name":"Ben"},"make":"BMW","model":"Aztek","value":3000,"year":2003} | |
{"index":{"_index":"play","_type":"type","_id":2}} | |
{"color":"black","driver":{"born":"1934-09-08","name":"Jon"},"make":"Mercedes","model":"Benz","value":10000,"year":2012} | |
{"index":{"_index":"play","_type":"type","_id":3}} | |
{"color":"green","driver":{"born":"1934-09-08","name":"Jon"},"make":"BMW","model":"Benz","value":10000,"year":2012} | |
' | |
# Do searches | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"query": { | |
"prefix": { | |
"driver.name": { | |
"value": "jon" | |
} | |
} | |
} | |
} | |
' | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"query": { | |
"prefix": { | |
"driver.name": { | |
"value": "Jon" | |
} | |
} | |
} | |
} | |
' | |
This file contains hidden or 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
# Auto generated by Found's Play-tool at 2013-11-24T18:00:25+01:00 | |
version: 0 | |
title: "prefix-query sample" | |
description: "Demo that \"prefix\"-query does not analyze the query text." |
This file contains hidden or 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
# In reply to http://stackoverflow.com/questions/20165164/elasticseach-no-results-for-json-query | |
query: | |
prefix: | |
driver.name: | |
# This should find docs 2 and 3. | |
value: jon | |
--- | |
query: | |
prefix: | |
driver.name: | |
# "jon" is what's indexed. This will not match. See the Analysis-tab. | |
value: Jon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment