杰克工作室 发表于 2023-2-28 14:45

ElasticSearch 6.x 学习小结(创建表/索引、添加数据)

废话不多说,直接上源码:这些数据格式,是在kibana格式化并且执行通过的。<br />
<br />
1、创建表(索引)
<pre>
请求:
PUT /user_search2
{
&quot;mappings&quot;: {
    &quot;user_search_keyword2&quot;: {
      &quot;properties&quot;: {
      &quot;id&quot;: {
          &quot;type&quot;: &quot;long&quot;
      },
      &quot;keyword_&quot;: {
          &quot;type&quot;: &quot;text&quot;
      },
      &quot;type_&quot;: {
          &quot;type&quot;: &quot;text&quot;
      },
      &quot;user_id&quot;: {
          &quot;type&quot;: &quot;long&quot;
      },
      &quot;create_time&quot;: {
          &quot;type&quot;: &quot;date&quot;
      }
      }
    }
}
}</pre>
<br />
返回结果:<br />
#! Deprecation: the default number of shards will change from to in 7.0.0; if you wish to continue using the default of shards, you must manage this on the create index request or with an index template<br />
{<br />
&nbsp; &quot;acknowledged&quot; : true,<br />
&nbsp; &quot;shards_acknowledged&quot; : true,<br />
&nbsp; &quot;index&quot; : &quot;user_search2&quot;<br />
}<br />
<br />
2、查询结构:<br />
请求:<br />
GET /user_search2/user_search_keyword2/_mapping
<pre>
返回结果:
{
&quot;user_search2&quot; : {
    &quot;mappings&quot; : {
      &quot;user_search_keyword2&quot; : {
      &quot;properties&quot; : {
          &quot;create_time&quot; : {
            &quot;type&quot; : &quot;date&quot;
          },
          &quot;id&quot; : {
            &quot;type&quot; : &quot;long&quot;
          },
          &quot;keyword_&quot; : {
            &quot;type&quot; : &quot;text&quot;
          },
          &quot;type_&quot; : {
            &quot;type&quot; : &quot;text&quot;
          },
          &quot;user_id&quot; : {
            &quot;type&quot; : &quot;long&quot;
          }
      }
      }
    }
}
}</pre>
<br />
3、添加测试数据
<pre>
请求:
POST /user_search2/user_search_keyword2
{
&quot;keyword_&quot;:&quot;我来测试下&quot;,
&quot;type_&quot;:&quot;article&quot;,
&quot;user_id&quot;:&quot;711260&quot;,
&quot;create_time&quot;:&quot;2018-12-18&quot;
}</pre>
返回结果:

<pre>
{
&quot;_index&quot; : &quot;user_search2&quot;,
&quot;_type&quot; : &quot;user_search_keyword2&quot;,
&quot;_id&quot; : &quot;Vpp1v2cBc3Sembhf9MFq&quot;,
&quot;_version&quot; : 1,
&quot;result&quot; : &quot;created&quot;,
&quot;_shards&quot; : {
    &quot;total&quot; : 2,
    &quot;successful&quot; : 2,
    &quot;failed&quot; : 0
},
&quot;_seq_no&quot; : 0,
&quot;_primary_term&quot; : 1
}</pre>
<br />
4、查看数据<br />
请求:<br />
GET /user_search2/user_search_keyword2/_search
<pre>
返回结果:
{
&quot;took&quot; : 1,
&quot;timed_out&quot; : false,
&quot;_shards&quot; : {
    &quot;total&quot; : 5,
    &quot;successful&quot; : 5,
    &quot;skipped&quot; : 0,
    &quot;failed&quot; : 0
},
&quot;hits&quot; : {
    &quot;total&quot; : 1,
    &quot;max_score&quot; : 1.0,
    &quot;hits&quot; : [
      {
      &quot;_index&quot; : &quot;user_search2&quot;,
      &quot;_type&quot; : &quot;user_search_keyword2&quot;,
      &quot;_id&quot; : &quot;Vpp1v2cBc3Sembhf9MFq&quot;,
      &quot;_score&quot; : 1.0,
      &quot;_source&quot; : {
          &quot;keyword_&quot; : &quot;我来测试下&quot;,
          &quot;type_&quot; : &quot;article&quot;,
          &quot;user_id&quot; : &quot;711260&quot;,
          &quot;create_time&quot; : &quot;2018-12-18&quot;
      }
      }
    ]
}
}</pre>
<br />
5、删除<br />
请求:<br />
DELETE /user_search2<br />
<br />
返回结果:<br />
{<br />
&nbsp; &quot;acknowledged&quot; : true<br />
}<br />
&nbsp;
页: [1]
查看完整版本: ElasticSearch 6.x 学习小结(创建表/索引、添加数据)