|
19 | 19 | package org.elasticsearch.index.analysis;
|
20 | 20 |
|
21 | 21 | import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
|
| 22 | +import org.elasticsearch.action.search.SearchResponse; |
22 | 23 | import org.elasticsearch.common.settings.ImmutableSettings;
|
23 | 24 | import org.elasticsearch.common.settings.Settings;
|
| 25 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 26 | +import org.elasticsearch.index.query.QueryBuilders; |
24 | 27 | import org.elasticsearch.plugins.PluginsService;
|
25 | 28 | import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
26 | 29 | import org.junit.Test;
|
27 | 30 |
|
| 31 | +import java.io.IOException; |
28 | 32 | import java.util.concurrent.ExecutionException;
|
29 | 33 |
|
| 34 | +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; |
30 | 35 | import static org.hamcrest.CoreMatchers.is;
|
31 | 36 | import static org.hamcrest.CoreMatchers.notNullValue;
|
32 | 37 |
|
@@ -56,4 +61,31 @@ public void testKuromojiAnalyzer() throws ExecutionException, InterruptedExcepti
|
56 | 61 | assertThat(response.getTokens().get(i).getTerm(), is(expectedTokens[i]));
|
57 | 62 | }
|
58 | 63 | }
|
| 64 | + |
| 65 | + @Test |
| 66 | + public void testKuromojiAnalyzerInMapping() throws ExecutionException, InterruptedException, IOException { |
| 67 | + createIndex("test"); |
| 68 | + ensureGreen("test"); |
| 69 | + final XContentBuilder mapping = jsonBuilder().startObject() |
| 70 | + .startObject("type") |
| 71 | + .startObject("properties") |
| 72 | + .startObject("foo") |
| 73 | + .field("type", "string") |
| 74 | + .field("analyzer", "kuromoji") |
| 75 | + .endObject() |
| 76 | + .endObject() |
| 77 | + .endObject() |
| 78 | + .endObject(); |
| 79 | + |
| 80 | + client().admin().indices().preparePutMapping("test").setType("type").setSource(mapping).get(); |
| 81 | + |
| 82 | + index("test", "type", "1", "foo", "JR新宿駅の近くにビールを飲みに行こうか"); |
| 83 | + refresh(); |
| 84 | + |
| 85 | + SearchResponse response = client().prepareSearch("test").setQuery( |
| 86 | + QueryBuilders.matchQuery("foo", "jr") |
| 87 | + ).execute().actionGet(); |
| 88 | + |
| 89 | + assertThat(response.getHits().getTotalHits(), is(1L)); |
| 90 | + } |
59 | 91 | }
|
0 commit comments