Last active
August 27, 2015 19:58
-
-
Save lfreneda/d120f45f6e6c612c7776 to your computer and use it in GitHub Desktop.
elasticsearch_index_people
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
# Delete the `people` index | |
DELETE /people | |
# Create the `people` index with proper settings | |
PUT /people | |
{ | |
"settings": { | |
"analysis": { | |
"filter": { | |
"brazilian_stop": { | |
"type": "stop", | |
"stopwords": "_brazilian_" | |
}, | |
"brazilian_stemmer": { | |
"type": "stemmer", | |
"language": "brazilian" | |
} | |
}, | |
"analyzer": { | |
"brazilian": { | |
"tokenizer": "standard", | |
"filter": [ | |
"lowercase", | |
"brazilian_stop", | |
"brazilian_stemmer" | |
] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"person": { | |
"properties": { | |
"name": { | |
"type": "multi_field", | |
"fields": { | |
"name": { | |
"type": "string", | |
"analyzer":"brazilian" | |
}, | |
"untouched": { | |
"type": "string", | |
"index" : "not_analyzed" | |
} | |
} | |
}, | |
"tags": { | |
"type": "string" | |
}, | |
"emails":{ | |
"type": "multi_field", | |
"fields": { | |
"email": { | |
"type": "string", | |
"index" : "analyzed", | |
"analyzer": "simple" | |
}, | |
"untouched":{ | |
"type": "string", | |
"index" : "not_analyzed" | |
} | |
} | |
}, | |
"phones":{ | |
"type": "multi_field", | |
"fields": { | |
"phones": { | |
"type": "string", | |
"index" : "analyzed", | |
"analyzer": "whitespace" | |
}, | |
"untouched":{ | |
"type": "string", | |
"index" : "not_analyzed" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
# Index some example docs | |
PUT /people/person/_bulk | |
{"index":{"_id":1}} | |
{"name":"Luiz Freneda", "phones":["11 963427193", "(11) 96342-7193"], "emails":["lfreneda@gmail.com"], "tags":["developer", "elasticsearcher", "cto"]} | |
{"index":{"_id":2}} | |
{"name":"Eduardo Santos", "emails":["eduardoluizsantos@gmail.com"], "tags":["developer", "ceo", "show-man"]} | |
{"index":{"_id":3}} | |
{"name":"Joao Sem acento", "emails":["joaosemacento@hotmail.com"], "tags":["user"]} | |
{"index":{"_id":4}} | |
{"name":"João Com acento", "emails":["joaocomacento@yahoo.com"], "tags":["user"]} | |
# Find people by name and tags | |
GET /people/person/_search | |
{ | |
"from":0, | |
"size":10, | |
"query":{ | |
"bool":{ | |
"should":[ | |
{ | |
"match":{ | |
"name":"Joao" | |
} | |
}, | |
{ | |
"regexp":{ | |
"name.untouched":"(.*)Jo[a|ã]o(.*)" | |
} | |
} | |
], | |
"must":[ | |
{ | |
"match":{ | |
"tags":"user" | |
} | |
} | |
], | |
"minimum_should_match":"100%" | |
} | |
}, | |
"highlight" : { | |
"pre_tags" : ["<b>"], | |
"post_tags" : ["</b>"], | |
"fields" : { | |
"name" : { | |
} | |
} | |
} | |
} | |
# Find people by pretty much everything haha | |
GET /people/person/_search | |
{ | |
"from":0, | |
"size":10, | |
"query":{ | |
"bool":{ | |
"should":[ | |
{ | |
"match":{ | |
"name":"963427193" | |
} | |
}, | |
{ | |
"regexp":{ | |
"name.untouched":"(.*)963427193(.*)" | |
} | |
} | |
, | |
{ | |
"regexp":{ | |
"emails.untouched":"(.*)963427193(.*)" | |
} | |
}, | |
{ | |
"regexp":{ | |
"phones.untouched":"(.*)963427193(.*)" | |
} | |
} | |
] | |
} | |
}, | |
"highlight" : { | |
"pre_tags" : ["<b>"], | |
"post_tags" : ["</b>"], | |
"fields" : { | |
"name" : { | |
}, | |
"email" : { | |
}, | |
"phones" : { | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment