Created
December 31, 2013 14:22
-
-
Save alexbrasetvik/8197442 to your computer and use it in GitHub Desktop.
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
user: John Smith | |
email: john.smith@gmail.com | |
--- | |
user: Alice Smith | |
email: john.smith@gmail.com | |
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/bash | |
export ELASTICSEARCH_ENDPOINT="http://localhost:9200" | |
# Create indexes | |
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{ | |
"settings": { | |
"analysis": {} | |
}, | |
"mappings": {} | |
}' | |
# Index documents | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d ' | |
{"index":{"_index":"play","_type":"type"}} | |
{"user":"John Smith","email":"john.smith@gmail.com"} | |
{"index":{"_index":"play","_type":"type"}} | |
{"user":"Alice Smith","email":"john.smith@gmail.com"} | |
' | |
# Do searches | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"query": { | |
"multi_match": { | |
"fields": [ | |
"user", | |
"email" | |
], | |
"query": "john Sm", | |
"operator": "and", | |
"type": "phrase_prefix" | |
} | |
} | |
} | |
' | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"query": { | |
"prefix": { | |
"user": { | |
"value": "John" | |
} | |
} | |
} | |
} | |
' | |
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
# Auto generated by Found's Play-tool at 2013-12-31T15:27:26+01:00 | |
version: 0 | |
title: multi_match with prefix | |
description: "" |
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
# In reply to http://stackoverflow.com/questions/20858404/multiple-fields-for-prefix-in-elasticsearch-and-auto-from-and-size-limit | |
query: | |
multi_match: | |
fields: | |
- user | |
query: john Sm | |
operator: and | |
type: phrase_prefix | |
--- | |
query: | |
prefix: | |
user: | |
# This does not match! "john" is what has been indexed. | |
value: John |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment