Created
December 24, 2013 00:47
-
-
Save alexbrasetvik/8107157 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
title: Female | |
--- | |
title: Female specimen | |
--- | |
title: Microscopic examination of specimen from female |
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": {} | |
}' | |
# Index documents | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d ' | |
{"index":{"_index":"play","_type":"type"}} | |
{"title":"Female"} | |
{"index":{"_index":"play","_type":"type"}} | |
{"title":"Female specimen"} | |
{"index":{"_index":"play","_type":"type"}} | |
{"title":"Microscopic examination of specimen from female"} | |
' | |
# Do searches | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"query": { | |
"prefix": { | |
"title": { | |
"prefix": "femal" | |
} | |
} | |
} | |
} | |
' | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"query": { | |
"span_first": { | |
"end": 1, | |
"match": { | |
"span_multi": { | |
"match": { | |
"prefix": { | |
"title": { | |
"prefix": "femal" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d ' | |
{ | |
"query": { | |
"bool": { | |
"should": [ | |
{ | |
"span_first": { | |
"end": 1, | |
"match": { | |
"span_multi": { | |
"match": { | |
"prefix": { | |
"title": { | |
"prefix": "femal" | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
{ | |
"match": { | |
"title": { | |
"query": "female" | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
' | |
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-24T02:00:22+01:00 | |
version: 0 | |
title: span_first to boost early matches | |
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/20748647/boosting-field-prefix-match-in-elasticsearch | |
# This will match all documents. | |
query: | |
prefix: | |
title: | |
prefix: femal | |
--- | |
# This matches only the two first documents. | |
query: | |
span_first: | |
end: 1 | |
match: | |
span_multi: | |
match: | |
prefix: | |
title: | |
prefix: femal | |
--- | |
# This matches all, but prefers the one's with a prefix match. | |
query: | |
bool: | |
should: | |
# It's sufficient that either of these match, but prefer that both matches. | |
- span_first: | |
end: 1 | |
match: | |
span_multi: | |
match: | |
prefix: | |
title: | |
prefix: femal | |
- match: | |
title: | |
query: female | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment