add tests for path mappings
This commit is contained in:
parent
fcf3697e51
commit
911d800ff8
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Licensed to Elastic Search and Shay Banon under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. Elastic Search licenses this
|
||||||
|
* file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.index.mapper.xcontent.path;
|
||||||
|
|
||||||
|
import org.elasticsearch.index.Index;
|
||||||
|
import org.elasticsearch.index.analysis.AnalysisService;
|
||||||
|
import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapper;
|
||||||
|
import org.elasticsearch.index.mapper.xcontent.XContentDocumentMapperParser;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.elasticsearch.util.io.Streams.*;
|
||||||
|
import static org.hamcrest.MatcherAssert.*;
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author kimchy (shay.banon)
|
||||||
|
*/
|
||||||
|
public class PathXContentMapperTests {
|
||||||
|
|
||||||
|
@Test public void testPathMapping() throws IOException {
|
||||||
|
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/path/test-mapping.json");
|
||||||
|
XContentDocumentMapper docMapper = (XContentDocumentMapper) new XContentDocumentMapperParser(new AnalysisService(new Index("test"))).parse(mapping);
|
||||||
|
|
||||||
|
assertThat(docMapper.mappers().indexName("first1"), notNullValue());
|
||||||
|
assertThat(docMapper.mappers().indexName("name1.first1"), nullValue());
|
||||||
|
assertThat(docMapper.mappers().indexName("last1"), notNullValue());
|
||||||
|
assertThat(docMapper.mappers().indexName("name1.last1"), nullValue());
|
||||||
|
|
||||||
|
assertThat(docMapper.mappers().indexName("first2"), nullValue());
|
||||||
|
assertThat(docMapper.mappers().indexName("name2.first2"), notNullValue());
|
||||||
|
assertThat(docMapper.mappers().indexName("last2"), nullValue());
|
||||||
|
assertThat(docMapper.mappers().indexName("name2.last2"), notNullValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"person" : {
|
||||||
|
"properties" : {
|
||||||
|
"name1" : {
|
||||||
|
"type" : "object",
|
||||||
|
"path" : "just_name",
|
||||||
|
"properties" : {
|
||||||
|
"first1" : {"type" : "string", "store" : "yes"},
|
||||||
|
"last1" : {"type" : "string", "index" : "not_analyzed"}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"name2" : {
|
||||||
|
"type" : "object",
|
||||||
|
"path" : "full",
|
||||||
|
"properties" : {
|
||||||
|
"first2" : {"type" : "string", "store" : "yes"},
|
||||||
|
"last2" : {"type" : "string", "index" : "not_analyzed"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue