Skip to content

Instantly share code, notes, and snippets.

@alexbrasetvik
Created December 31, 2013 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbrasetvik/8197442 to your computer and use it in GitHub Desktop.
Save alexbrasetvik/8197442 to your computer and use it in GitHub Desktop.
user: John Smith
email: john.smith@gmail.com
---
user: Alice Smith
email: john.smith@gmail.com
#!/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"
}
}
}
}
'
# Auto generated by Found's Play-tool at 2013-12-31T15:27:26+01:00
version: 0
title: multi_match with prefix
description: ""
# 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
- email
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