-
-
Save ankitkr/e7776419b0e8ff5334af to your computer and use it in GitHub Desktop.
Deleted documents show up in completion suggester
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
#!/bin/bash | |
ES='localhost:9200'; | |
create_index(){ | |
curl -XPUT "$ES/completionsuggester?pretty=true" -d' | |
{ | |
"settings": { | |
"index": { | |
"number_of_shards": 1, | |
"number_of_replicas": 1 | |
}, | |
"analysis": { | |
"tokenizer":{ | |
"ngram_tokenizer_search":{ | |
"type": "edgeNgram", | |
"min_gram": 3, | |
"max_gram": 7, | |
"token_chars": ["letter","digit"] | |
}, | |
"ngram_tokenizer":{ | |
"type": "nGram", | |
"min_gram": 1, | |
"max_gram": 7, | |
"token_chars": ["letter","digit"] | |
} | |
}, | |
"analyzer": { | |
"word_analyzer_search": { | |
"type": "custom", | |
"tokenizer": "ngram_tokenizer_search", | |
"filter": ["lowercase"] | |
}, | |
"word_analyzer": { | |
"type": "custom", | |
"tokenizer": "ngram_tokenizer", | |
"filter": ["lowercase"] | |
}, | |
"autocomplete_analyzer": { | |
"type": "custom", | |
"tokenizer": "whitespace", | |
"filter": ["lowercase","word_delimiter"] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"complete": { | |
"properties": { | |
"project_name": { | |
"type": "string", | |
"index_analyzer": "word_analyzer", | |
"search_analyzer": "word_analyzer_search" | |
}, | |
"project_autocomplete_list": { | |
"type": "completion", | |
"payloads": true, | |
"preserve_position_increments": false | |
} | |
} | |
} | |
} | |
}'; | |
} | |
# Index some docs | |
index_doc1() { | |
curl -XPOST "$ES/completionsuggester/complete/1?pretty=true" -d' | |
{ | |
"project_name":"Bluebird of Your Mind", | |
"project_autocomplete_list" : [{ | |
"input": [ | |
"Bangalore_Bluebird", | |
"Bangalore_Bluebird of", | |
"Bangalore_of", | |
"Bangalore_Bluebird of Your", | |
"Bangalore_of Your", | |
"Bangalore_Your", | |
"Bangalore_Bluebird of Your Mind", | |
"Bangalore_of Your Mind", | |
"Bangalore_Your Mind", | |
"Bangalore_Mind", | |
"Bangalore_Whitefield", | |
"Bangalore_Some" | |
], | |
"weight":55, | |
"payload": { | |
"id":1, | |
"name":"Bluebird of Your Mind", | |
"project_class":"B", | |
"locality_id":66, | |
"locality_name":"Whitefield", | |
"builder_id":9, | |
"builder_name":"Some", | |
"builder_logo":"www.ankitkumar.in" | |
}, | |
"output":"Bluebird of Your Mind"}] | |
}'; | |
} | |
index_doc2() { | |
for i in {101..4000}; do | |
curl -XPOST "$ES/completionsuggester/complete/$i?pretty=true" -d' | |
{ | |
"project_name":"Nahar Amrit Shakti", | |
"project_autocomplete_list" : [{ | |
"input": [ | |
"Bangalore_Nshar", | |
"Bangalore_Nahar Amrit", | |
"Bangalore_Amrit", | |
"Bangalore_Nahar Amrit Shakti", | |
"Bangalore_Amrit Shakti", | |
"Bangalore_Shakti", | |
"Bangalore_Electronic", | |
"Bangalore_Any" | |
], | |
"weight":55, | |
"payload": { | |
"id":2, | |
"name":"Nahar Amrit Shakti", | |
"project_class":"C", | |
"locality_id":61, | |
"locality_name":"Electronic", | |
"builder_id":1, | |
"builder_name":"Any", | |
"builder_logo":"www.ankit.in" | |
}, | |
"output":"Nahar Amrit Shakti"}] | |
}'; | |
done | |
} | |
use_suggester() { | |
curl -XPOST "$ES/completionsuggester/_suggest?pretty=true" -d ' | |
{ | |
"project_suggest": { | |
"text": "Bangalore_Bluebird", | |
"completion": { | |
"field": "project_autocomplete_list" | |
} | |
} | |
}'; | |
} | |
delete_doc() { | |
curl -XDELETE "$ES/completionsuggester/complete/1?pretty=true" | |
} | |
# Create Index | |
create_index; | |
index_doc1; | |
index_doc2; | |
delete_doc; | |
curl -XGET "$ES/completionsuggester/complete/1?pretty=true" | |
curl -XPOST "$ES/completionsuggester/_suggest?pretty=true" -d ' | |
{ | |
"project_suggest": { | |
"text": "Bangalore_Bluebird", | |
"completion": { | |
"field": "project_autocomplete_list" | |
} | |
} | |
}'; | |
# Refresh index | |
curl -XPOST "$ES/completionsuggester/_refresh"; | |
curl -XGET "$ES/completionsuggester/complete/1?pretty=true" | |
curl -XPOST "$ES/completionsuggester/_suggest?pretty=true" -d ' | |
{ | |
"project_suggest": { | |
"text": "Bangalore_Bluebird", | |
"completion": { | |
"field": "project_autocomplete_list" | |
} | |
} | |
}'; | |
#Optimize Index | |
curl -XPOST "$ES/completionsuggester/_optimize"; | |
curl -XGET "$ES/completionsuggester/complete/1?pretty=true" | |
curl -XPOST "$ES/completionsuggester/_suggest?pretty=true" -d ' | |
{ | |
"project_suggest": { | |
"text": "Bangalore_Bluebird", | |
"completion": { | |
"field": "project_autocomplete_list" | |
} | |
} | |
}'; |
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
curl -XGET 'localhost:9200' | |
{ | |
"status" : 200, | |
"name" : "Arlok", | |
"version" : { | |
"number" : "1.0.3", | |
"build_hash" : "61bfb72d845a59a58cd9910e47515665f6478a5c", | |
"build_timestamp" : "2014-04-16T14:43:11Z", | |
"build_snapshot" : false, | |
"lucene_version" : "4.6" | |
}, | |
"tagline" : "You Know, for Search" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment