ElasticSearch在搜索处理经纬度的时候,需要根据经纬度来返回周边距离内的一些环境,一开始设置的经纬度为text
,一直报错,坑死我了,拜访了很多大佬后,终于得出标准的解决方案;
地理位置需要声明为特殊的类型, 不显示在mapping中定义的话, 需要写成如下形式;
{
"building" : {
"location_map" : {
"lat" : 40.12,
"lon" : -71.34
},
"tag" : ["food", "family"],
"text" : "my favorite family restaurant"
}
}
但是最好显示约定在mapping中定义, 可以声明为 geo_point格式,具体如下;
{
"building" : {
"properties" : {
"location" : {
"type" : "geo_point"
}
}
}
}
关于ES文档内text
类型的field(属性)
你可以,我的版本7.7.1
测试下来,在mapping中不管申明不声明分词器的模式,只要在读取数据GET
部分声明了,都可以达到分词的效果,如图1,图2;
DELETE ik_test
PUT ik_test
{
"mappings":
{
"properties":
{
"name":
{
"type":"text"
,"analyzer": "ik_smart"
,"search_analyzer": "ik_max_word"
}
}
}
}
GET /ik_test/_analyze
{
"analyzer": "ik_max_word",
"text": "搜索引擎"
}
效果代码;
# DELETE ik_test
{
"acknowledged" : true
}
# PUT ik_test
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "ik_test"
}
# GET /ik_test/_analyze
{
"tokens" : [
{
"token" : "搜索引擎",
"start_offset" : 0,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 0
},
{
"token" : "搜索",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 1
},
{
"token" : "索引",
"start_offset" : 1,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 2
},
{
"token" : "引擎",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 3
}
]
}