Last active
          June 26, 2017 10:29 
        
      - 
      
 - 
        
Save Lackoftactics/a8503c5cb75eff8667023d4003d12cbc to your computer and use it in GitHub Desktop.  
    Elasticsearch
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | curl -X PUT localhost:9200/books -d ' | |
| { | |
| "settings" : { | |
| "index" : { | |
| "analysis" : { | |
| "analyzer" : { | |
| "autocomplete_analyzer" : { | |
| "type" : "custom", | |
| "tokenizer" : "lowercase", | |
| "filter" : ["asciifolding", "title_ngram"] | |
| } | |
| }, | |
| "filter" : { | |
| "title_ngram" : { | |
| "type" : "nGram", | |
| "min_gram" : 3, | |
| "max_gram" : 5 | |
| } | |
| } | |
| } | |
| } | |
| }, | |
| "mappings": { | |
| "title": { | |
| "properties": { | |
| "title": { | |
| "type": "string", | |
| "analyzer": "autocomplete_analyzer" | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ' | |
| curl "http://localhost:9200/books/_search?q=title=The" | |
| Using cross fields | |
| curl localhost:9200/books/_search -d ' | |
| { | |
| "query": { | |
| "multi_match": { | |
| "query": "Witness western", | |
| "type": "cross_fields", | |
| "fields": ["title^2", "genre"] | |
| } | |
| } | |
| } | |
| ' | |
| Boosting fields | |
| Boost books which have classic genre | |
| curl localhost:9200/books/_search -d ' | |
| { | |
| "query": { | |
| "bool": { | |
| "must": { | |
| "match": { | |
| "title": { | |
| "query": "Trees", | |
| "operator": "and" | |
| } | |
| } | |
| }, | |
| "should": [ | |
| { "match": { | |
| "genre": { | |
| "query": "crime", | |
| "boost": 3 | |
| } | |
| }} | |
| ] | |
| } | |
| } | |
| } | |
| ' | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment