Skip to content

Instantly share code, notes, and snippets.

@nayelisantacruz
Created September 18, 2013 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nayelisantacruz/6610862 to your computer and use it in GitHub Desktop.
Save nayelisantacruz/6610862 to your computer and use it in GitHub Desktop.
Elasticsearch - faceting tests
curl -X DELETE localhost:9200/myindex
curl -X PUT "http://localhost:9200/myindex" -d '
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"autocomplete": {
"tokenizer": "whitespace",
"filter": [
"lowercase",
"engram"
]
}
},
"filter": {
"engram": {
"type": "edgeNGram",
"min_gram": 1,
"max_gram": 10
}
}
}
}
},
"mappings": {
"posts": {
"properties": {
"title": {
"type": "multi_field",
"fields": {
"title": {
"type": "string",
"index": "not_analyzed",
"store": "yes"
},
"autocomplete": {
"type": "string",
"index_analyzer": "autocomplete",
"index": "analyzed",
"search_analyzer": "standard"
}
}
},
"content": {
"type": "string",
"store":"yes"
}
}
}
}
}
'
curl -X PUT "http://localhost:9200/myindex/posts/1" -d '
{"title": "Java Platform, Standard Edition", "content": "Java Platform, Standard Edition or Java SE is a widely used platform for development and deployment of portable applications for desktop and server environments.[1] Java SE uses object-oriented Java programming language. Strictly speaking, Java SE is a platform specification."}
'
curl -X PUT "http://localhost:9200/myindex/posts/2" -d '
{"title": "JavaScript", "content": "JavaScript (JS) is an interpreted computer programming language.[5] As part of web browsers, implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed.[5] It has also become common in server-side programming, game development and the creation of desktop applications."}'
curl -X PUT "http://localhost:9200/myindex/posts/3" -d '
{"title": "jQuery", "content": "jQuery is a multi-browser (cf. cross-browser) JavaScript library designed to simplify the client-side scripting of HTML.[2] It was released in January 2006 at BarCamp NYC by John Resig. It is currently developed by a team of developers led by Dave Methvin. Used by over 65% of the 10,000 most visited websites, jQuery is the most popular JavaScript library in use today."}
'
curl -X PUT "http://localhost:9200/myindex/posts/4" -d '
{"title": "Python (programming language)", "content": "Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library."}
'
curl -X PUT "http://localhost:9200/myindex/posts/5" -d '
{"title": "Ajax", "content": "Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display, and allow the user to interact with, the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads."}
'
curl -X PUT "http://localhost:9200/myindex/posts/6" -d '
{"title": "HTML5", "content": "HTML5 is a markup language used for structuring and presenting content for the World Wide Web and a core technology of the Internet. It is the fifth revision of the HTML standard (created in 1990 and standardized as HTML 4 as of 1997)[2] and, as of December 2012, is a candidate recommendation of the World Wide Web Consortium (W3C)."}
'
curl -X PUT "http://localhost:9200/myindex/posts/7" -d '
{"title": "MongoDB", "content": "MongoDB (from "humongous") is a cross-platform document-oriented database system. Classified as a "NoSQL" database, MongoDB eschews the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster."}
'
curl -X PUT "http://localhost:9200/myindex/posts/7" -d '
{"title": "ElasticSearch", "content": "ElasticSearch is a distributed, RESTful, free/open source search server based on Apache Lucene. It is developed by Shay Banon[1] and is released under the terms of the Apache License. ElasticSearch is developed in Java."}
'
curl -XGET 'localhost:9200/myindex/posts/_mapping?pretty=true'
curl -XGET 'localhost:9200/myindex/posts/_search?pretty=true'
curl -XGET "localhost:9200/myindex/_search" -d '
{
"size": 0,
"query": {
"term": {
"title.autocomplete": "java"
}
},
"facets": {
"title": {
"terms": {
"field": "title"
}
}
},
"sort": [
{
"_score": "desc"
}
],
"highlight": {
"require_field_match": true,
"fields": {
"title": {
"pre_tags": [
"<b>"
],
"post_tags": [
"</b>"
]
},
"content": {
"pre_tags": [
"<b>"
],
"post_tags": [
"</b>"
]
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment