ElasticSearch入门-Get Mapping

2019-03-11 09:26|来源: 网络

想要在Java API中获得一个mapping 还真困难,以此铭记。

Java代码
  1. import org.elasticsearch.client.Client;  

  2. import org.elasticsearch.cluster.ClusterState;  

  3. import org.elasticsearch.cluster.metadata.IndexMetaData;  

  4. import org.elasticsearch.cluster.metadata.MappingMetaData;  

  5.  

  6. import com.donlianli.es.ESUtils;  

  7. public class GetMappingTest {  

  8.    public static void  main(String[] argv) throws Exception{  

  9.        Client client = ESUtils.getClient();  

  10.          

  11.        ClusterState cs = client.admin().cluster().prepareState()  

  12.                //索引库名称为testIndex  

  13.                .setFilterIndices("test").execute().actionGet().getState();  

  14.          

  15.        IndexMetaData imd = cs.getMetaData()  

  16.                //这个名称同上面的名称  

  17.                .index("test");  

  18.        //type的名称  

  19.        MappingMetaData mdd = imd.mapping("test");  

  20.        System.out.println(mdd.sourceAsMap());  

  21.    }  

  22. }  

 
转自:http://donlianli.iteye.com/blog/1921151

相关问答

更多
  • Mapping,就是对索引库中索引的字段名及其数据类型进行定义,类似于关系数据库中表建立时要定义字段名及其数据类型那样,不过es的mapping比数据库灵活很多,它可以动态添加字段。一般不需要要指定mapping都可以,因为es会自动根据数据格式定义它的类型,如果你需要对某些字段添加特殊属性(如:定义使用其它分词器、是否分词、是否存储等),就必须手动添加mapping。有两种添加mapping的方法,一种是定义在配置文件中,一种是运行时手动提交mapping,两种选一种就行了。 先介绍在配置文件中定义map ...
  • Mapping,就是对索引库中索引的字段名及其数据类型进行定义,类似于关系数据库中表建立时要定义字段名及其数据类型那样,不过es的mapping比数据库灵活很多,它可以动态添加字段。一般不需要要指定mapping都可以,因为es会自动根据数据格式定义它的类型,如果你需要对某些字段添加特殊属性(如:定义使用其它分词器、是否分词、是否存储等),就必须手动添加mapping。有两种添加mapping的方法,一种是定义在配置文件中,一种是运行时手动提交mapping,两种选一种就行了。 先介绍在配置文件中定义map ...
  • 您正在寻找索引的索引模板 。 我认为您可以使用正则表达式匹配您的索引名称,并自动按模板创建索引映射,如: PUT _template/template_1 { "template": "\d\d\d\d-\d\d-\d\d", //index name match You are looking for Index Templates for indexes. I think you can use regex to match your index name, and automatically c ...
  • 在Kibana的/config/kibana.yml配置文件中,您有这个条目: # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values. # The default is 'localhost', which usually means remote machines will not be able to connect. # To all ...
  • 你不应该使用 TypeExists defined on the interface IElasticClient 代替? 我的意思是如果类型存在,那么该类型的映射也存在。 I figured it out. The issue was that I had set up the client to throw exceptions on failure instead of allowing the IsValid to be what determines success. var connectio ...
  • 你确定在PUT中你确实传递了json请求的主体吗? 看起来你正在做一个空体的PUT,它只创建索引而不是映射。 Are you sure that in the PUT you are actually passing the body of the json request? It seems that you are doing a PUT with an empty body, that create only the index and not the mapping.
  • 当您从头开始,因此没有映射时,您依赖于默认值。 每次发送文档时,尚未映射的字段将根据其json类型(以及日期约定)自动映射。 也就是说,如果您将第一个文档中的字段作为数字发送,并且该字段在第二个文档中成为字符串,则第二个文档的索引操作将返回错误。 有管理映射的api,这并不意味着您必须声明所有字段。 您可以只指定要与默认行为不同的行为。 您可以在创建索引时指定映射,如果索引已存在,则使用put mapping api ,或者甚至在索引模板中包含它们,以用于尚未创建的索引。 可以更改映射,但只能应用向后兼容的 ...
  • 创建索引后,您似乎没有索引任何数据。 对_analyze的调用不会对任何内容编制索引,只是简单地向您展示如何分析您发送给ES的内容。 首先,您需要通过指定使用您定义的分析器的映射来创建索引: curl -XPUT 'http://localhost:9200/aida' -d '{ "settings": { "analysis": { "analyzer": { "my_analyzer": { "tokenizer": "standard", ...
  • fielddata似乎是具有"type" : "text"的text字段的属性"type" : "text" fielddata seems to be a property of text fields which have "type" : "text"
  • 您在源代码中看到的内容,即形式为"1485281760000"的字符串式时间戳不会更改,并且始终会反映您发送给Elasticsearch的完全相同的JSON。 但是,在索引时,字符串"1485281760000"将被解释并索引为长值1485281760000 。 如果您要更改JSON源,而是使用长时间戳而不是字符串时间戳(如下所示)发送,则源将显示您的长时间戳。 ... "last_post_date": 1485281760000, ... 长话短说: 您在_source看到的正是您发送给ES的内容 源 ...