Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Delete the `my_index` index
- DELETE /people
- # Map the `postcode` to be not_analyzed
- 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"
- },
- "email":{
- "type": "multi_field",
- "fields": {
- "email": {
- "type": "string",
- "index" : "analyzed",
- "analyzer": "simple"
- },
- "untouched":{
- "type": "string",
- "index" : "not_analyzed"
- }
- }
- }
- }
- }
- }
- }
- # Index some example docs
- PUT /people/person/_bulk
- {"index":{"_id":1}}
- {"name":"Luiz Freneda", "email":"lfreneda@gmail.com", "tags":["developer", "elasticsearcher", "cto"]}
- {"index":{"_id":2}}
- {"name":"Eduardo Santos", "email":"eduardoluizsantos@gmail.com", "tags":["developer", "ceo", "show-man"]}
- {"index":{"_id":3}}
- {"name":"Joao Sem acento", "email":"joaosemacento@hotmail.com", "tags":["user"]}
- {"index":{"_id":4}}
- {"name":"João Com acento", "email":"joaocomacento@yahoo.com", "tags":["user"]}
- # Find people by emails
- GET /people/person/_search
- {
- "from":0,
- "size":10,
- "query":{
- "simple_query_string": {
- "query": "name:(lfreneda) OR email:(lfreneda)",
- "flags" : "OR|AND|PREFIX"
- }
- },
- "highlight" : {
- "pre_tags" : ["<b>"],
- "post_tags" : ["</b>"],
- "fields" : {
- "name" : {
- "fragment_size": 20,
- "number_of_fragments": 3
- },
- "email":{
- "fragment_size": 20,
- "number_of_fragments": 3
- }
- }
- }
- }
- # 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" : {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement