Skip to content

Instantly share code, notes, and snippets.

@nkvoll
Created December 9, 2013 11:12
Show Gist options
  • Save nkvoll/7870684 to your computer and use it in GitHub Desktop.
Save nkvoll/7870684 to your computer and use it in GitHub Desktop.
analyzer:
casesensitive:
type: custom
tokenizer: standard
filter: [standard, stop]
title: Metastatic Lung Cancer
tags:
- MET
- Lung
- HGF
---
title: "Colorectal kras c.12345G>T"
tags:
- PTEN Loss
- colorectal
- KRAS
---
title: Colorectal Kras
tags:
- colorectal
- "KRAS c.12345G>T"
test:
properties:
title:
type: multi_field
fields:
title:
type: string
title.cased:
type: string
analyzer: casesensitive
tags:
type: multi_field
fields:
tags:
type: string
tags.cased:
type: string
analyzer: casesensitive
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"settings": {
"analysis": {
"analyzer": {
"casesensitive": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"standard",
"stop"
]
}
}
}
},
"mappings": {
"test": {
"properties": {
"title": {
"type": "multi_field",
"fields": {
"title": {
"type": "string"
},
"title.cased": {
"type": "string",
"analyzer": "casesensitive"
}
}
},
"tags": {
"type": "multi_field",
"fields": {
"tags": {
"type": "string"
},
"tags.cased": {
"type": "string",
"analyzer": "casesensitive"
}
}
}
}
}
}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type"}}
{"title":"Metastatic Lung Cancer","tags":["MET","Lung","HGF"]}
{"index":{"_index":"play","_type":"type"}}
{"title":"Colorectal kras c.12345G>T","tags":["PTEN Loss","colorectal","KRAS"]}
{"index":{"_index":"play","_type":"type"}}
{"title":"Colorectal Kras","tags":["colorectal","KRAS c.12345G>T"]}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"filter": {
"query": {
"multi_match": {
"fields": [
"title",
"tags"
],
"query": "met",
"type": "phrase",
"analyzer": "casesensitive"
}
}
}
}
'
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"filter": {
"query": {
"multi_match": {
"fields": [
"title",
"tags"
],
"query": "MET",
"type": "phrase",
"analyzer": "casesensitive"
}
}
}
}
'
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"filter": {
"query": {
"multi_match": {
"fields": [
"title.cased",
"tags.cased"
],
"query": "met",
"type": "phrase",
"analyzer": "casesensitive"
}
}
}
}
'
# Auto generated by Found's Play-tool at 2013-12-09T12:15:50+01:00
version: 0
title: "Multi-match case sensitive analyzer"
description: ""
filter:
query:
multi_match:
fields: [title, tags]
query: met
type: phrase
analyzer: casesensitive
---
filter:
query:
multi_match:
fields: [title, tags]
query: MET
type: phrase
analyzer: casesensitive
---
filter:
query:
multi_match:
fields: [title.cased, tags.cased]
query: met
type: phrase
analyzer: casesensitive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment