Skip to content

Commit

Permalink
Created a unit test, that MetaModel is unable to work with a document…
Browse files Browse the repository at this point in the history
… indexed by Elasticsearch which contains dots in its fieldnames. Note that this is actually caused by Elasticsearch, because the mapping returned for such a document by Elasticsearch doesn't match the source returned by Elasticsearch when getting the source of a search hit. (see elastic/elasticsearch-hadoop#853 and related issues for more info on this).
  • Loading branch information
Arjan Seijkens committed Jul 3, 2020
1 parent 27fbbb4 commit 3988fbb
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.common.xcontent.XContentType;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -111,4 +112,38 @@ public void testNestedData() throws Exception {
assertEquals("Main street 1, Newville", userValueMap.get("address"));
}
}

@Test
public void testIndexOfDocumentWithDots() throws Exception {
final String document =
"{ \"user.fullname\": \"John Doe\", "
+ "\"user.address\": \"Main street 1, Newville\", "
+ "\"message\": \"This is what I have to say.\" }";

final IndexRequest indexRequest = new IndexRequest(INDEX_NAME).id("1");
indexRequest.source(document, XContentType.JSON);

client.index(indexRequest, RequestOptions.DEFAULT);

final Table table = dataContext.getDefaultSchema().getTableByName(DEFAULT_TABLE_NAME);

assertThat(table.getColumnNames(), containsInAnyOrder("_id", "message", "user"));

dataContext.refreshSchemas();

try (final DataSet dataSet = dataContext
.query()
.from(DEFAULT_TABLE_NAME)
.select("user")
.and("message")
.execute()) {
assertEquals(ElasticSearchRestDataSet.class, dataSet.getClass());

assertTrue(dataSet.next());
final Row row = dataSet.getRow();
assertEquals("This is what I have to say.", row.getValue(table.getColumnByName("message")));

assertNotNull(row.getValue(table.getColumnByName("user")));
}
}
}

0 comments on commit 3988fbb

Please sign in to comment.