es - elasticsearch mapping - field data type - 16

177 阅读1分钟

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个追求完美的过程。

问 :annotated_text有什么特点?
答 :
在这里插入图片描述

问 :annotated_text如何使用?
答 :

# anatated-text
PUT /annotated_test
{
  "mappings" : {
    "properties" : {
      "my_annotated_text" : {"type" : "annotated_text"}
    }
  }
}

# 测试
GET /annotated_test/_analyze
{
  "field" : "my_annotated_text",
  "text"  : ["[Jeff Beck](Jeff+Beck&Guitarist) plays a strat"]
}

# 结果
{
  "tokens" : [
    {
      "token" : "Jeff Beck",
      "start_offset" : 0,
      "end_offset" : 9,
      "type" : "annotation",
      "position" : 0,
      "positionLength" : 2
    },
    {
      "token" : "Guitarist",
      "start_offset" : 0,
      "end_offset" : 9,
      "type" : "annotation",
      "position" : 0,
      "positionLength" : 2
    },
    {
      "token" : "jeff",
      "start_offset" : 0,
      "end_offset" : 4,
      "type" : "<ALPHANUM>",
      "position" : 0
    },
    {
      "token" : "beck",
      "start_offset" : 5,
      "end_offset" : 9,
      "type" : "<ALPHANUM>",
      "position" : 1
    },
    {
      "token" : "plays",
      "start_offset" : 10,
      "end_offset" : 15,
      "type" : "<ALPHANUM>",
      "position" : 2
    },
    {
      "token" : "a",
      "start_offset" : 16,
      "end_offset" : 17,
      "type" : "<ALPHANUM>",
      "position" : 3
    },
    {
      "token" : "strat",
      "start_offset" : 18,
      "end_offset" : 23,
      "type" : "<ALPHANUM>",
      "position" : 4
    }
  ]
}


# 索引
POST /annotated_test/_doc
{
  "my_annotated_text" : "[Beck](Beck) announced a new tour"
}

# 索引
POST /annotated_test/_doc
{
  "my_annotated_text" : "[Jeff Beck](Jeff+Beck&Guitarist) plays a strat"
}

# 索引
POST /annotated_test/_doc
{
  "my_annotated_text" : "[Jeff Beck](Jeff+Beck&Jeff+Guitarist) plays a strat"
}

# 搜索
GET /annotated_test/_search
{
  "query" : {
    "term" : {
      "my_annotated_text" : {
        "value" : "Jeff Guitarist"
      }
    }
  }
}

# 结果
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0925692,
    "hits" : [
      {
        "_index" : "annotated_test",
        "_type" : "_doc",
        "_id" : "L6bUPXgBgXknW_r_k3WK",
        "_score" : 1.0925692,
        "_source" : {
          "my_annotated_text" : "[Jeff Beck](Jeff+Beck&Jeff+Guitarist) plays a strat"
        }
      }
    ]
  }
}


# 搜索
GET /annotated_test/_search
{
  "query" : {
    "term" : {
      "my_annotated_text" : {
        "value" : "Guitarist"
      }
    }
  }
}

# 结果
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0925692,
    "hits" : [
      {
        "_index" : "annotated_test",
        "_type" : "_doc",
        "_id" : "LqbQPXgBgXknW_r_iXVt",
        "_score" : 1.0925692,
        "_source" : {
          "my_annotated_text" : "[Jeff Beck](Jeff+Beck&Guitarist) plays a strat"
        }
      }
    ]
  }
}


# 搜索
GET /annotated_test/_search
{
  "query" : {
    "term" : {
      "my_annotated_text" : {
        "value" : "Beck"
      }
    }
  }
}

# 结果
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0925692,
    "hits" : [
      {
        "_index" : "annotated_test",
        "_type" : "_doc",
        "_id" : "LabQPXgBgXknW_r_fnWL",
        "_score" : 1.0925692,
        "_source" : {
          "my_annotated_text" : "[Beck](Beck) announced a new tour"
        }
      }
    ]
  }
}

# 搜索
GET /annotated_test/_search
{
  "query" : {
    "term" : {
      "my_annotated_text" : {
        "value" : "Jeff Beck"
      }
    }
  }
}

# 结果
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.52354836,
    "hits" : [
      {
        "_index" : "annotated_test",
        "_type" : "_doc",
        "_id" : "LqbQPXgBgXknW_r_iXVt",
        "_score" : 0.52354836,
        "_source" : {
          "my_annotated_text" : "[Jeff Beck](Jeff+Beck&Guitarist) plays a strat"
        }
      },
      {
        "_index" : "annotated_test",
        "_type" : "_doc",
        "_id" : "L6bUPXgBgXknW_r_k3WK",
        "_score" : 0.52354836,
        "_source" : {
          "my_annotated_text" : "[Jeff Beck](Jeff+Beck&Jeff+Guitarist) plays a strat"
        }
      }
    ]
  }
}