Skip to content

Instantly share code, notes, and snippets.

@luizgpsantos
Last active August 29, 2015 14:17
Show Gist options
  • Save luizgpsantos/46165f10cfdecfc6aa4f to your computer and use it in GitHub Desktop.
Save luizgpsantos/46165f10cfdecfc6aa4f to your computer and use it in GitHub Desktop.

Revisions

  1. luizgpsantos revised this gist Mar 26, 2015. 2 changed files with 15 additions and 12 deletions.
    16 changes: 15 additions & 1 deletion indexar_documentos.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,17 @@
    curl -XPOST "http://localhost:9200/index_name" -d'
    {
    "mappings": {
    "your_type": {
    "properties": {
    "colours": {
    "type": "string",
    "index": "not_analyzed"
    }
    }
    }
    }
    }'

    curl -XPOST "http://localhost:9200/index_name/your_type/person1" -d'
    {
    "name": "ben",
    @@ -16,7 +30,7 @@ curl -XPOST "http://localhost:9200/index_name/your_type/person3" -d'
    {
    "name": "clark",
    "age": 22,
    "colours": ["azul", "marron", "verde"]
    "colours": ["azul", "amarelo-torrado", "verde"]
    }'

    curl -XPOST "http://localhost:9200/index_name/your_type/person4" -d'
    11 changes: 0 additions & 11 deletions pesquisa.sh
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,3 @@
    # Maneira mais simples:
    curl -XPOST "http://localhost:9200/index_name/your_type/_search" -d'
    {
    "query": {
    "match": {
    "colours": "azul amarelo rosa"
    }
    }
    }'

    # Ou se você quiser mais explícito:
    curl -XPOST "http://localhost:9200/index_name/your_type/_search" -d'
    {
    "query": {
  2. luizgpsantos created this gist Mar 26, 2015.
    27 changes: 27 additions & 0 deletions indexar_documentos.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    curl -XPOST "http://localhost:9200/index_name/your_type/person1" -d'
    {
    "name": "ben",
    "age": 30,
    "colours": ["azul", "amarelo", "preto"]
    }'

    curl -XPOST "http://localhost:9200/index_name/your_type/person2" -d'
    {
    "name": "linda",
    "age": 10,
    "colours": ["preto", "branco", "verde"]
    }'

    curl -XPOST "http://localhost:9200/index_name/your_type/person3" -d'
    {
    "name": "clark",
    "age": 22,
    "colours": ["azul", "marron", "verde"]
    }'

    curl -XPOST "http://localhost:9200/index_name/your_type/person4" -d'
    {
    "name": "jerry",
    "age": 20,
    "colours": ["laranja", "amarelo", "branco"]
    }'
    35 changes: 35 additions & 0 deletions pesquisa.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    # Maneira mais simples:
    curl -XPOST "http://localhost:9200/index_name/your_type/_search" -d'
    {
    "query": {
    "match": {
    "colours": "azul amarelo rosa"
    }
    }
    }'

    # Ou se você quiser mais explícito:
    curl -XPOST "http://localhost:9200/index_name/your_type/_search" -d'
    {
    "query": {
    "bool": {
    "should": [
    {
    "match": {
    "colours": "azul"
    }
    },
    {
    "match": {
    "colours": "amarelo"
    }
    },
    {
    "match": {
    "colours": "rosa"
    }
    }
    ]
    }
    }
    }'