{"id":19206,"date":"2013-11-27T01:48:51","date_gmt":"2013-11-26T23:48:51","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=19206"},"modified":"2013-11-27T01:48:51","modified_gmt":"2013-11-26T23:48:51","slug":"getting-started-with-spring-data-solr","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html","title":{"rendered":"Getting started with Spring Data Solr"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/spring-projects\/spring-data-solr\" rel=\"nofollow\">Spring Data Solr<\/a> is an extension to the Spring Data project which aims to simplify the usage of <a href=\"http:\/\/lucene.apache.org\/solr\/\" rel=\"nofollow\">Apache Solr<\/a> in Spring applications. Please note that this is not an introduction into Spring (Data) or Solr. I assume you have at least some basic understanding of both technologies. Within the following post I will show how you can use Spring Data repositories to access Solr features in Spring applications.<\/p>\n<h2>Configuration<\/h2>\n<p>First we need a running Solr server. For simplicity reasons we will use the example configuration that comes with the current Solr release (4.5.1 at the time I am writing) and is described in the official <a href=\"http:\/\/lucene.apache.org\/solr\/4_5_1\/tutorial.html\" rel=\"nofollow\">Solr tutorial<\/a>. So we only have to download Solr, extract it in a directory of our choice and then run java -jar start.jar from the &lt;solr home&gt;\/example directory.<\/p>\n<p>Now let&#8217;s move to our demo application and add the Spring Data Solr dependency using maven:<\/p>\n<pre class=\" brush:xml\">&lt;dependency&gt;\r\n\u00a0\u00a0&lt;groupId&gt;org.springframework.data&lt;\/groupId&gt;\r\n\u00a0\u00a0&lt;artifactId&gt;spring-data-solr&lt;\/artifactId&gt;\r\n\u00a0\u00a0&lt;version&gt;1.0.0.RELEASE&lt;\/version&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>In this example I am using Spring Boot to set up a small example Spring application. I am using the following Spring Boot dependencies and the Spring Boot parent pom for this:<\/p>\n<pre class=\" brush:xml\">&lt;parent&gt;\r\n\u00a0\u00a0&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\u00a0\u00a0&lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\r\n\u00a0\u00a0&lt;version&gt;0.5.0.BUILD-SNAPSHOT&lt;\/version&gt;\r\n&lt;\/parent&gt;<\/pre>\n<pre class=\" brush:xml\">&lt;dependency&gt;\r\n\u00a0\u00a0&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\u00a0\u00a0&lt;artifactId&gt;spring-boot-starter&lt;\/artifactId&gt;\r\n&lt;\/dependency&gt;\r\n&lt;dependency&gt;\r\n\u00a0\u00a0&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\r\n\u00a0\u00a0&lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\r\n\u00a0\u00a0&lt;scope&gt;test&lt;\/scope&gt;\r\n&lt;\/dependency&gt;<\/pre>\n<p>Don&#8217;t worry if you haven&#8217;t used Spring Boot yet. These dependencies mainly act as shortcut for common (Spring) dependencies and simplify the configuration a bit. If you want to integrate Spring Data Solr within an existing Spring application you can skip the Spring Boot dependencies.<\/p>\n<p>The Spring bean configuration is quite simple, we only have to define two beans ourself:<\/p>\n<pre class=\" brush:java\">@ComponentScan\r\n@EnableSolrRepositories(\"com.mscharhag.solr.repository\")\r\npublic\u00a0class\u00a0Application\u00a0{\r\n\r\n\u00a0\u00a0@Bean\r\n\u00a0\u00a0public\u00a0SolrServer\u00a0solrServer()\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0return\u00a0new\u00a0HttpSolrServer(\"http:\/\/localhost:8983\/solr\");\r\n\u00a0\u00a0}\r\n\r\n\u00a0\u00a0@Bean\r\n\u00a0\u00a0public\u00a0SolrTemplate\u00a0solrTemplate(SolrServer\u00a0server)\u00a0throws\u00a0Exception\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0return\u00a0new\u00a0SolrTemplate(server);\r\n\u00a0\u00a0}\r\n}<\/pre>\n<p>The solrServer bean is used to connect to the running Solr instance. Since Spring Data Solr uses <a href=\"http:\/\/wiki.apache.org\/solr\/Solrj\">Solrj<\/a> we create a Solrj <a href=\"http:\/\/lucene.apache.org\/solr\/4_5_1\/solr-solrj\/org\/apache\/solr\/client\/solrj\/impl\/HttpSolrServer.html\" rel=\"nofollow\">HttpSolrServer<\/a> instance. It would also be possible to use an embedded Solr server by using <a href=\"http:\/\/lucene.apache.org\/solr\/4_5_1\/solr-core\/org\/apache\/solr\/client\/solrj\/embedded\/EmbeddedSolrServer.html\" rel=\"nofollow\">EmbeddedSolrServer<\/a>. The SolrTemplate provides common functionality to work with Solr (similar to Spring&#8217;s JdbcTemplate). A solrTemplate bean is required for creating Solr repositories. Please also note the @EnableSolrRepositories annotation. With this annotation we tell Spring Data Solr to look in the specified package for Solr repositories.<\/p>\n<h2>Creating a document<\/h2>\n<p>Before we can query Solr we have to add documents to the index. To define a document we create a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Plain_Old_Java_Object\" rel=\"nofollow\">POJO<\/a> and add Solrj annotations to it. In this example we will use a simple Book class as document:<\/p>\n<pre class=\" brush:java\">public\u00a0class\u00a0Book\u00a0{\r\n\r\n\u00a0\u00a0@Field\r\n\u00a0\u00a0private\u00a0String\u00a0id;\r\n\r\n\u00a0\u00a0@Field\r\n\u00a0\u00a0private\u00a0String\u00a0name;\r\n\r\n\u00a0\u00a0@Field\r\n\u00a0\u00a0private\u00a0String\u00a0description;\r\n\r\n\u00a0\u00a0@Field(\"categories_txt\")\r\n\u00a0\u00a0private\u00a0List&lt;Category&gt;\u00a0categories;\r\n\r\n\u00a0\u00a0\/\/\u00a0getters\/setters\r\n}<\/pre>\n<pre class=\" brush:java\">public\u00a0enum\u00a0Category\u00a0{\r\n\u00a0\u00a0EDUCATION,\u00a0HISTORY,\u00a0HUMOR,\u00a0TECHNOLOGY,\u00a0ROMANCE,\u00a0ADVENTURE\r\n}<\/pre>\n<p>Each book has a unique id, a name, a description and belongs to one or more categories. Note that Solr requires a unique ID of type String for each document by default. Fields that should be added to the Solr index are annotated with the Solrj <a href=\"http:\/\/lucene.apache.org\/solr\/4_5_1\/solr-solrj\/org\/apache\/solr\/client\/solrj\/beans\/Field.html\" rel=\"nofollow\">@Field<\/a> annotation. By default Solrj tries to map document field names to Solr fields of the same name. The Solr example configuration already defines Solr fields named id, name and description so it should not be necessary to add these fields to the Solr configuration.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>In case you want to change the Solr field definitions you can find the example configuration file at &lt;solr home&gt;\/example\/solr\/collection1\/conf\/schema.xml. Within this file you should find the following field definitions:<\/p>\n<pre class=\" brush:java\">&lt;field\u00a0name=\"id\"\u00a0type=\"string\"\u00a0indexed=\"true\"\u00a0stored=\"true\"\u00a0required=\"true\"\u00a0multiValued=\"false\"\u00a0\/&gt;\u00a0\r\n&lt;field\u00a0name=\"name\"\u00a0type=\"text_general\"\u00a0indexed=\"true\"\u00a0stored=\"true\"\u00a0\/&gt;\r\n&lt;field\u00a0name=\"description\"\u00a0type=\"text_general\"\u00a0indexed=\"true\"\u00a0stored=\"true\"\/&gt;<\/pre>\n<p>In general title would be a better attribute name for a Book than name. However, by using name we can use the default Solr field configuration. So I go for name instead of title for simplicity reasons.<\/p>\n<p>For categories we have to define the field name manually using the @Field annotation: categories_txt. This matches the dynamic field named *_txt from the Solr example. This field definition can also be found in schema.xml:<\/p>\n<pre class=\" brush:xml\">&lt;dynamicField\u00a0name=\"*_txt\"\u00a0type=\"text_general\"\u00a0\u00a0\u00a0indexed=\"true\"\u00a0\u00a0stored=\"true\"\u00a0multiValued=\"true\"\/&gt;<\/pre>\n<h2>Creating a repository<\/h2>\n<p>Spring Data uses repositories to simplify the usage of various data access technologies. A repository is basically an interface whose implementation is dynamically generated by Spring Data on application start. The generated implementation is based on naming conventions used in the repository interface. If this is new to you I recommend reading <a href=\"http:\/\/docs.spring.io\/spring-data\/jpa\/docs\/1.4.2.RELEASE\/reference\/html\/repositories.html\" rel=\"nofollow\">Working with Spring Data Repositories<\/a>.<\/p>\n<p>Spring Data Solr uses the same approach. We use naming conventions and annotations inside interfaces to define the methods we need to access Solr features. We start with a simple repository that contains only one method (we will add more later):<\/p>\n<pre class=\" brush:java\">public\u00a0interface\u00a0BookRepository\u00a0extends\u00a0SolrCrudRepository&lt;Book,\u00a0String&gt;\u00a0{\r\n\r\n\u00a0\u00a0List&lt;Book&gt;\u00a0findByName(String\u00a0name);\r\n\r\n}<\/pre>\n<p>We get some common methods like save(), findAll(), delete() or count() in the repository by extending SolrCrudRepository. With the definition of the interface method findByName(String name) we tell Spring Data Solr to create a method implementation that queries Solr for a list of books. The book names in this list should match the passed parameter.<\/p>\n<p>The repository implementation can be injected into other classes using Spring&#8217;s DI functionality. In this example we inject the repository into a simple JUnit test:<\/p>\n<pre class=\" brush:java\">@RunWith(SpringJUnit4ClassRunner.class)\r\n@ContextConfiguration(classes\u00a0=\u00a0Application.class,\u00a0loader=SpringApplicationContextLoader.class)\r\npublic\u00a0class\u00a0BookRepositoryTests\u00a0{\r\n\r\n\u00a0\u00a0@Autowired\r\n\u00a0\u00a0private\u00a0BookRepository\u00a0bookRepository;\r\n\r\n\u00a0\u00a0...\r\n}<\/pre>\n<h2>Adding a document to Solr<\/h2>\n<p>Now it is time to add some books to Solr. Using our repository this is a very easy job:<\/p>\n<pre class=\" brush:java\">private\u00a0void\u00a0addBookToIndex(String\u00a0name,\u00a0String\u00a0description,\u00a0Category...\u00a0categories)\u00a0{\r\n\u00a0\u00a0Book\u00a0book\u00a0=\u00a0new\u00a0Book();\r\n\u00a0\u00a0book.setName(name);\r\n\u00a0\u00a0book.setDescription(description);\r\n\u00a0\u00a0book.setCategories(Arrays.asList(categories));\r\n\u00a0\u00a0book.setId(UUID.randomUUID().toString());\r\n\u00a0\u00a0bookRepository.save(book);\r\n}\r\n\r\nprivate\u00a0void\u00a0createSampleData()\u00a0{\r\n\u00a0\u00a0addBookToIndex(\"Treasure\u00a0Island\",\u00a0\"Best\u00a0seller\u00a0by\u00a0R.L.S.\", Category.ADVENTURE);\r\n\u00a0\u00a0addBookToIndex(\"The\u00a0Pirate\u00a0Island\",\u00a0\"Oh\u00a0noes,\u00a0the\u00a0pirates\u00a0are\u00a0coming!\", Category.ADVENTURE, Category.HUMOR);\r\n\u00a0\u00a0...\r\n}<\/pre>\n<h2>Adding pagination and boosting<\/h2>\n<p>Assume we have an application where users are able to search for books. We need to find books whose name or description match the search query given by the user. For performance reasons we want to add some kind of pagination which shows only 10 search results at once to the user.<\/p>\n<p>Let&#8217;s create a new method in our repository interface for this:<\/p>\n<pre class=\" brush:java\">Page&lt;Book&gt;\u00a0findByNameOrDescription(@Boost(2)\u00a0String\u00a0name,\u00a0String\u00a0description,\u00a0Pageable\u00a0pageable);<\/pre>\n<p>The method name findByNameOrDescription tells Spring Data Solr to query for book objects whose name or description match the passed parameters. To support pagination we added the Pageable parameter and changed the return type from List&lt;Book&gt; to Page&lt;Book&gt;. By adding the @Boost annotation to the name parameter we are boosting books whose name matches the search parameter. This makes sense because those books are typically at higher Interest for the user.<\/p>\n<p>If we now want to query for the first page containing 10 elements we just have to do:<\/p>\n<pre class=\" brush:java\">Page&lt;Book&gt;\u00a0booksPage\u00a0=\u00a0bookRepository.findByNameOrDescription\r\n(searchString,\u00a0searchString,\u00a0new\u00a0PageRequest(0,\u00a010));<\/pre>\n<p>Besides the first 10 search results Page&lt;Book&gt; provides some useful methods for building pagination functionality:<\/p>\n<pre class=\" brush:java\">booksPage.getContent()\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0get\u00a0a\u00a0list\u00a0of\u00a0(max)\u00a010\u00a0books\r\nbooksPage.getTotalElements() \/\/\u00a0total\u00a0number\u00a0of\u00a0elements\u00a0(can\u00a0be\u00a0&gt;10)\r\nbooksPage.getTotalPages()\u00a0\u00a0\u00a0\u00a0\/\/\u00a0total\u00a0number\u00a0of\u00a0pages\r\nbooksPage.getNumber()\u00a0\u00a0\u00a0\u00a0\u00a0  \u00a0\/\/\u00a0current\u00a0page\u00a0number\r\nbooksPage.isFirstPage()\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0true\u00a0if\u00a0this\u00a0is\u00a0the\u00a0first\u00a0page\r\nbooksPage.hasNextPage()\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0true\u00a0if\u00a0another\u00a0page\u00a0is\u00a0available\r\nbooksPage.nextPageable()\u00a0\u00a0\u00a0\u00a0 \/\/\u00a0the\u00a0pageable\u00a0for\u00a0requesting\u00a0the\u00a0next\u00a0page\r\n...<\/pre>\n<h2>Faceting<\/h2>\n<p>Whenever a user searches for a book name we want to show him how many books matching the given query parameter are available in the different categories. This feature is called <a href=\"http:\/\/en.wikipedia.org\/wiki\/Faceted_search\" rel=\"nofollow\">faceted search<\/a> and directly supported by Spring Data Solr. We just have to add another method to our repository interface:<\/p>\n<pre class=\" brush:java\">@Query(\"name:?0\")\r\n@Facet(fields\u00a0=\u00a0{\u00a0\"categories_txt\"\u00a0},\u00a0limit\u00a0=\u00a05)\r\nFacetPage&lt;Book&gt;\u00a0findByNameAndFacetOnCategories(String\u00a0name,\u00a0Pageable\u00a0page);<\/pre>\n<p>This time the query will be derived from the @Query annotation (containing the Solr query) instead of the method name. With the @Facet annotation we tell Spring Data Solr to facet books by categories and return the first five facets.<\/p>\n<p>It would also be possible to remove the @Query annotation and change the method name to findByName for the same effect. The small disadvantage in this approach is that it is not obvious to the caller that this repository method does perform facetting. Addionally the method signature might collide with other methods that search books by name.<\/p>\n<p><strong>Usage:<\/strong><\/p>\n<pre class=\"brush: java;wrap-lines: false\">FacetPage&lt;Book&gt;\u00a0booksFacetPage\u00a0=\u00a0bookRepository.findByNameAndFacetOnCategories(bookName,\u00a0new\u00a0PageRequest(0,\u00a010));\r\n\r\nbooksFacetPage.getContent();\u00a0\/\/\u00a0the\u00a0first\u00a010\u00a0books\r\n\r\nfor\u00a0(Page&lt;?\u00a0extends\u00a0FacetEntry&gt;\u00a0page\u00a0:\u00a0booksFacetPage.getAllFacets())\u00a0{\r\n\u00a0\u00a0for\u00a0(FacetEntry\u00a0facetEntry\u00a0:\u00a0page.getContent())\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0String\u00a0categoryName\u00a0=\u00a0facetEntry.getValue();\u00a0 \/\/\u00a0name\u00a0of\u00a0the\u00a0category\r\n\u00a0\u00a0\u00a0\u00a0long\u00a0count\u00a0=\u00a0facetEntry.getValueCount();\u00a0\u00a0\u00a0\u00a0  \/\/\u00a0number\u00a0of\u00a0books\u00a0in\u00a0this\u00a0category\r\n\r\n\u00a0\u00a0\u00a0\u00a0\/\/\u00a0convert\u00a0the\u00a0category\u00a0name\u00a0back\u00a0to\u00a0an\u00a0enum\r\n\u00a0\u00a0\u00a0\u00a0Category\u00a0category\u00a0=\u00a0Category.valueOf(categoryName.toUpperCase());\r\n\u00a0 }\r\n}<\/pre>\n<p>Note that booksFacetPage.getAllFacets() returns a Collection of FacetEntry pages. This is because the @Facet annotation allows you to facet multiple fields at once. Each FacetPage contains max. five FacetEntries (defined by the limit attribute of @Facet).<\/p>\n<h2>Highlighting<\/h2>\n<p>Often it is useful to highlight the search query occurrences in the list of search results (like it is done by google or bing). This can be achieved with the highlighting feature of (Spring Data) Solr.<\/p>\n<p>Let&#8217;s add another repository method:<\/p>\n<pre class=\"brush: java;wrap-lines: false\">@Highlight(prefix\u00a0=\u00a0\"&lt;highlight&gt;\",\u00a0postfix\u00a0=\u00a0\"&lt;\/highlight&gt;\")\r\nHighlightPage&lt;Book&gt;\u00a0findByDescription(String\u00a0description,\u00a0Pageable\u00a0pageable);<\/pre>\n<p>The @Highlight annotation tells Solr to highlight to occurrences of the searched description.<\/p>\n<p><strong>Usage:<\/strong><\/p>\n<pre class=\"brush: java;wrap-lines: false\">HighlightPage&lt;Book&gt;\u00a0booksHighlightPage\u00a0=\u00a0bookRepository.findByDescription(description,\u00a0new\u00a0PageRequest(0,\u00a010));\r\n\r\nbooksHighlightPage.getContent();\u00a0\/\/\u00a0first\u00a010\u00a0books\r\n\r\nfor\u00a0(HighlightEntry&lt;Book&gt;\u00a0he\u00a0:\u00a0booksHighlightPage.getHighlighted())\u00a0{\r\n\u00a0\u00a0\/\/\u00a0A\u00a0HighlightEntry\u00a0belongs\u00a0to\u00a0an\u00a0Entity\u00a0(Book)\u00a0and\u00a0may\u00a0have\u00a0multiple\u00a0highlighted\u00a0fields\u00a0(description)\r\n\u00a0\u00a0for\u00a0(Highlight\u00a0highlight\u00a0:\u00a0he.getHighlights())\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\/\/\u00a0Each\u00a0highlight\u00a0might\u00a0have\u00a0multiple\u00a0occurrences\u00a0within\u00a0the\u00a0description\r\n\u00a0\u00a0\u00a0\u00a0for\u00a0(String\u00a0snipplet\u00a0:\u00a0highlight.getSnipplets())\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ snipplet contains the highlighted text\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0}\r\n}<\/pre>\n<p>If you use this repository method to query for books whose description contains the string <i>Treasure Island<\/i> a snipplet might look like this:<\/p>\n<pre class=\"brush: java;wrap-lines: false\">&lt;highlight&gt;Treasure\u00a0Island&lt;\/highlight&gt;\u00a0is\u00a0a\u00a0tale\u00a0of\u00a0pirates\u00a0and\u00a0villains,\u00a0maps,\u00a0treasure\u00a0and\u00a0shipwreck,\u00a0and\u00a0is\u00a0perhaps\u00a0one\u00a0of\u00a0the\u00a0best\u00a0adventure\u00a0story\u00a0ever\u00a0written.<\/pre>\n<p>In this case\u00a0 <i>Treasure Island<\/i> is located at the beginning of the description and is highlighted with the prefix and postfix defined in the @Highlight annotation. This additional markup can be used to mark query occurrences when the search results are shown to the user.<\/p>\n<h2>Conclusion<\/h2>\n<p>Spring Data Solr provides a very simple way to integrate Solr into Spring applications. With the repository abstraction it follows the same design principle most other Spring Data project do. The only small drawback I faced while playing around with Spring Data Solr was the documentation that could be improved here and there.<\/p>\n<ul>\n<li>You can find the complete source code for this example on <a href=\"https:\/\/github.com\/mscharhag\/Spring-data-solr-example\">GitHub<\/a>.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div style=\"border: 1px solid #D8D8D8; background: #FAFAFA; width: 100%; padding-left: 5px;\"><b><i>Reference: <\/i><\/b><a href=\"http:\/\/www.mscharhag.com\/2013\/11\/getting-started-with-spring-data-solr.html\">Getting started with Spring Data Solr<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\">JCG partner<\/a> Michael Scharhag at the <a href=\"http:\/\/www.mscharhag.com\/\">mscharhag, Programming and Stuff<\/a> blog.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Spring Data Solr is an extension to the Spring Data project which aims to simplify the usage of Apache Solr in Spring applications. Please note that this is not an introduction into Spring (Data) or Solr. I assume you have at least some basic understanding of both technologies. Within the following post I will show &hellip;<\/p>\n","protected":false},"author":514,"featured_media":80,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[470,30,321],"class_list":["post-19206","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-apache-solr","tag-spring","tag-spring-data"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Getting started with Spring Data Solr<\/title>\n<meta name=\"description\" content=\"Spring Data Solr is an extension to the Spring Data project which aims to simplify the usage of Apache Solr in Spring applications. Please note that this\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting started with Spring Data Solr\" \/>\n<meta property=\"og:description\" content=\"Spring Data Solr is an extension to the Spring Data project which aims to simplify the usage of Apache Solr in Spring applications. Please note that this\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-11-26T23:48:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Scharhag\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/mscharhag\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Scharhag\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html\"},\"author\":{\"name\":\"Michael Scharhag\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0f0f81e875d40e3f820392e0ffce65d1\"},\"headline\":\"Getting started with Spring Data Solr\",\"datePublished\":\"2013-11-26T23:48:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html\"},\"wordCount\":1367,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-solr-logo.jpg\",\"keywords\":[\"Apache Solr\",\"Spring\",\"Spring Data\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html\",\"name\":\"Getting started with Spring Data Solr\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-solr-logo.jpg\",\"datePublished\":\"2013-11-26T23:48:51+00:00\",\"description\":\"Spring Data Solr is an extension to the Spring Data project which aims to simplify the usage of Apache Solr in Spring applications. Please note that this\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-solr-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/apache-solr-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/11\\\/getting-started-with-spring-data-solr.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Getting started with Spring Data Solr\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0f0f81e875d40e3f820392e0ffce65d1\",\"name\":\"Michael Scharhag\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g\",\"caption\":\"Michael Scharhag\"},\"description\":\"Michael Scharhag is a Java Developer, Blogger and technology enthusiast. Particularly interested in Java related technologies including Java EE, Spring, Groovy and Grails.\",\"sameAs\":[\"http:\\\/\\\/www.mscharhag.com\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/mscharhag\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/michael-scharhag\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getting started with Spring Data Solr","description":"Spring Data Solr is an extension to the Spring Data project which aims to simplify the usage of Apache Solr in Spring applications. Please note that this","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html","og_locale":"en_US","og_type":"article","og_title":"Getting started with Spring Data Solr","og_description":"Spring Data Solr is an extension to the Spring Data project which aims to simplify the usage of Apache Solr in Spring applications. Please note that this","og_url":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-11-26T23:48:51+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","type":"image\/jpeg"}],"author":"Michael Scharhag","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/mscharhag","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Michael Scharhag","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html"},"author":{"name":"Michael Scharhag","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0f0f81e875d40e3f820392e0ffce65d1"},"headline":"Getting started with Spring Data Solr","datePublished":"2013-11-26T23:48:51+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html"},"wordCount":1367,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","keywords":["Apache Solr","Spring","Spring Data"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html","url":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html","name":"Getting started with Spring Data Solr","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","datePublished":"2013-11-26T23:48:51+00:00","description":"Spring Data Solr is an extension to the Spring Data project which aims to simplify the usage of Apache Solr in Spring applications. Please note that this","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/apache-solr-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/11\/getting-started-with-spring-data-solr.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Getting started with Spring Data Solr"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0f0f81e875d40e3f820392e0ffce65d1","name":"Michael Scharhag","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/52283459bfc820fb6a66704b3eccc771a1d8a63a0bdbbe1651bb5cb383a42148?s=96&d=mm&r=g","caption":"Michael Scharhag"},"description":"Michael Scharhag is a Java Developer, Blogger and technology enthusiast. Particularly interested in Java related technologies including Java EE, Spring, Groovy and Grails.","sameAs":["http:\/\/www.mscharhag.com\/","https:\/\/x.com\/https:\/\/twitter.com\/mscharhag"],"url":"https:\/\/www.javacodegeeks.com\/author\/michael-scharhag"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/19206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/514"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=19206"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/19206\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/80"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=19206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=19206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=19206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}