Created
December 6, 2013 08:06
-
-
Save dqduc/7820194 to your computer and use it in GitHub Desktop.
Script for http://stackoverflow.com/questions/20331845/how-to-query-all-fields-individually-with-elasticsearch
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 -X DELETE localhost:9200/myindex2 | |
curl -X PUT localhost:9200/myindex2 -d ' | |
{ | |
"settings" : { | |
"index":{ | |
"number_of_replicas":1, | |
"number_of_shards":4, | |
"analysis":{ | |
"analyzer":{ | |
"index_analyzer":{ | |
"type" : "custom", | |
"tokenizer" : "standard", | |
"filter": ["lowercase", "snowball", "metaphone_phonetic"] | |
}, | |
"search_analyzer":{ | |
"type" : "custom", | |
"tokenizer" : "standard", | |
"filter": ["lowercase", "snowball", "metaphone_phonetic"] | |
}, | |
"description_analyzer":{ | |
"type" : "custom", | |
"tokenizer" : "standard", | |
"filter": ["metaphone_phonetic", "snowball"] | |
}, | |
"domain_name_analyzer":{ | |
"type" : "custom", | |
"tokenizer" : "domain_ngram_tokenizer", | |
"filter": ["lowercase"] | |
} | |
}, | |
"tokenizer" : { | |
"domain_ngram_tokenizer" : { | |
"type" : "nGram", | |
"min_gram" : "4", | |
"max_gram" : "45" | |
} | |
}, | |
"filter" : { | |
"metaphone_phonetic" : { | |
"type" : "phonetic", | |
"encoder": "metaphone", | |
"replace" : false | |
} | |
} | |
} | |
} | |
}, | |
"mappings" : { | |
"product" : { | |
"index_analyzer" : "index_analyzer", | |
"search_analyzer" : "search_analyzer", | |
"properties" : { | |
"client_comments" : { | |
"type" : "string" | |
}, | |
"client_id" : { | |
"type" : "integer", | |
"index" : "no" | |
}, | |
"client_name" : { | |
"type" : "string", | |
"boost" : 3.0 | |
}, | |
"cluster_name" : { | |
"type" : "string", | |
"index" : "no" | |
}, | |
"comments" : { | |
"type" : "string" | |
}, | |
"domains" : { | |
"type" : "string", | |
"index_analyzer" : "domain_name_analyzer" | |
}, | |
"external_ip" : { | |
"type" : "ip", | |
"index" : "analyzed" | |
}, | |
"id" : { | |
"type" : "integer", | |
"index" : "no" | |
}, | |
"primary_domain" : { | |
"type" : "string", | |
"index" : "no" | |
}, | |
"test_site" : { | |
"type" : "boolean", | |
"index" : "no" | |
} | |
} | |
} | |
} | |
}' | |
# Now, index data | |
curl -X POST 'localhost:9200/myindex2/product' -d '{ | |
"comments" : "Some text with armschel", | |
"domains" : "abc.com" | |
}' | |
curl -X POST 'localhost:9200/myindex2/product' -d '{ | |
"comments" : "Some other text", | |
"domains" : "armschel.com" | |
}' | |
curl -X POST 'localhost:9200/myindex2/product' -d '{ | |
"comments" : "Some more text", | |
"domains" : "def.com" | |
}' | |
curl -XPOST "http://localhost:9200/myindex2/_refresh" | |
curl -XGET "http://localhost:9200/myindex2/product/_search" -d '{ | |
"query": { | |
"query_string": { | |
"default_field": "_all", | |
"query": "armschel" | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment