Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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": {
- "_routing": {
- "required": true,
- "path": "accountId"
- },
- "properties": {
- "accountId": {
- "type": "string",
- "index" : "not_analyzed"
- },
- "firstName": {
- "type": "multi_field",
- "fields": {
- "firstName": {
- "type": "string",
- "analyzer":"brazilian"
- },
- "untouched": {
- "type": "string",
- "index" : "not_analyzed"
- }
- }
- },
- "lastName": {
- "type": "multi_field",
- "fields": {
- "lastName": {
- "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}}
- {"firstName":"Luiz", "lastName": "Freneda", "phones":["(11) 96342-7193"], "emails":["l.freneda@gmail.com"], "tags":["developer", "elasticsearcher", "cto"]}
- {"index":{"_id":2}}
- {"firstName":"Eduardo", "lastName": "Santos", "emails":["eduardoluizsantos@gmail.com"], "tags":["developer", "ceo", "show-man"]}
- {"index":{"_id":3}}
- {"firstName":"Joao", "lastName": "Sem acento", "emails":["joaosemacento@hotmail.com"], "tags":["user"]}
- {"index":{"_id":4}}
- {"firstName":"João", "lastName": "Com acento", "emails":["joaocomacento@yahoo.com"], "tags":["user"]}
- }
- GET /people/person/_search
- {
- "from": 0,
- "size": 10,
- "highlight": {
- "pre_tags": [
- "<b>"
- ],
- "post_tags": [
- "</b>"
- ],
- "fields": {
- "firstName": {},
- "lastName": {},
- "emails": {},
- "phones": {}
- }
- },
- "query": {
- "bool":{
- "should":[
- { "match":{ "firstName":"Luciano" } },
- { "regexp":{ "firstName.untouched":"(.*)Luci[a|ã|á|à]n[o|ó|õ](.*)" } },
- { "match":{ "lastName":"Luciano" } },
- { "regexp":{ "lastName.untouched":"(.*)Luci[a|ã|á|à]n[o|ó|õ](.*)" } },
- { "regexp":{ "emails.untouched":"(.*)Luciano(.*)" } },
- { "regexp":{ "phones.untouched":"(.*)00000000000(.*)" } }
- ]
- ,"must":[ { "terms":{ "tags":["vip","carlos"] } } ], "minimum_should_match":"17%"}
- }
- }
- # Find people by name and tags
- GET /people/person/_search
- {
- "from":0,
- "size":10,
- "query":{
- "bool":{
- "should":[
- {
- "match":{
- "firstName":"Luciano"
- }
- },
- {
- "match":{
- "lastName":"Luciano"
- }
- },
- {
- "regexp":{
- "firstName.untouched":"(.*)Luciano(.*)"
- }
- },
- {
- "regexp":{
- "lastName.untouched":"(.*)Luciano(.*)"
- }
- }
- ,
- {
- "regexp":{
- "emails.untouched":"(.*)Luciano(.*)"
- }
- },
- {
- "regexp":{
- "phones.untouched":"(.*)Luciano(.*)"
- }
- }
- ],
- "must":[
- {
- "terms":{
- "tags":["vip","carlos"]
- }
- }
- ],
- "minimum_should_match":"17%"
- }
- },
- "highlight" : {
- "pre_tags" : ["<b>"],
- "post_tags" : ["</b>"],
- "fields" : {
- "name" : {
- }
- }
- }
- }
- GET /people/person/_search
- {
- "from": 0,
- "size": 15,
- "highlight": {
- "pre_tags": [
- "<b>"
- ],
- "post_tags": [
- "</b>"
- ],
- "fields": {
- "name": {},
- "emails": {},
- "phones": {}
- }
- },
- "query": {
- "bool": {
- "should": [
- {
- "match": {
- "name": {
- "query": "Joao"
- }
- }
- },
- {
- "regexp": {
- "name.untouched": {
- "value": "(.*)Joao(.*)"
- }
- }
- },
- {
- "regexp": {
- "emails.untouched": {
- "value": "(.*)Joao(.*)"
- }
- }
- },
- {
- "regexp": {
- "phones.untouched": {
- "value": "(.*)Joao(.*)"
- }
- }
- }
- ]
- }
- }
- }
- # Find people by pretty much everything haha
- GET /people/person/_search
- {
- "from":0,
- "size":10,
- "query":{
- "bool":{
- "should":[
- {
- "match":{
- "name":"6733267977"
- }
- },
- {
- "regexp":{
- "name.untouched":"(.*)6733267977(.*)"
- }
- }
- ,
- {
- "regexp":{
- "emails.untouched":"(.*)6733267977(.*)"
- }
- },
- {
- "regexp":{
- "phones.untouched":"(.*)6733267977(.*)"
- }
- }
- ]
- }
- },
- "highlight" : {
- "pre_tags" : ["<b>"],
- "post_tags" : ["</b>"],
- "fields" : {
- "name" : {
- },
- "email" : {
- },
- "phones" : {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement