Skip to content

Instantly share code, notes, and snippets.

@alexbrasetvik
Created December 24, 2013 00:47
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/8107157 to your computer and use it in GitHub Desktop.
Save alexbrasetvik/8107157 to your computer and use it in GitHub Desktop.
title: Female
---
title: Female specimen
---
title: Microscopic examination of specimen from female
#!/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"
}
}
}
]
}
}
}
'
# 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: ""
# 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