es - elasticsearch mapping - parameters - index_options

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

问 :index_options有什么特点?
答 :
在这里插入图片描述
问 :index_options如何使用?
答 :

# index_options
PUT /index_options_test
{
  "mappings" : {
    "properties" : {
      "name" : {
        "type"          : "text",
        "index_options" : "positions",
        "fields"        : {
          "doc" : {
            "type"          : "text",
            "index_options" : "docs"
          },
          "freq" : {
            "type"          : "text",
            "index_options" : "freqs"
          },
          "offset" : {
            "type"          : "text",
            "index_options" : "offsets"
          }
        }
      }
    }
  }
}

# 索引
POST /index_options_test/_doc/1
{
  "name" : "hello good me"
}

# 索引
POST /index_options_test/_doc/2
{
  "name" : "hello hello good me"
}


# 搜索, positions - 默认
GET /index_options_test/_search
{
  "query" : {
    "match" : {
      "name" : "hello"
    }
  }
}

# 结果
{
  "took" : 10,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.24100877,
    "hits" : [
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.24100877,
        "_source" : {
          "name" : "hello hello good me"
        }
      },
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.19363807,
        "_source" : {
          "name" : "hello good me"
        }
      }
    ]
  }
}

# 搜索,docs - 不通过词频评分
GET /index_options_test/_search
{
  "query" : {
    "match" : {
      "name.doc" : "hello"
    }
  }
}

# 结果
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.18232156,
    "hits" : [
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.18232156,
        "_source" : {
          "name" : "hello good me"
        }
      },
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.18232156,
        "_source" : {
          "name" : "hello hello good me"
        }
      }
    ]
  }
}


# 搜索,freqs - 通过词频评分
GET /index_options_test/_search
{
  "query" : {
    "match" : {
      "name.freq" : "hello"
    }
  }
}

# 结果
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.24100877,
    "hits" : [
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.24100877,
        "_source" : {
          "name" : "hello hello good me"
        }
      },
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.19363807,
        "_source" : {
          "name" : "hello good me"
        }
      }
    ]
  }
}


# 搜索,positions - 支持短语查询
GET /index_options_test/_search
{
  "query" : {
    "match_phrase" : {
      "name" : "hello good"
    }
  }
}

# 结果
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.38727614,
    "hits" : [
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.38727614,
        "_source" : {
          "name" : "hello good me"
        }
      },
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.34450948,
        "_source" : {
          "name" : "hello hello good me"
        }
      }
    ]
  }
}


# 搜索,docs - 不支持短语查询
GET /index_options_test/_search
{
  "query" : {
    "match_phrase" : {
      "name.doc" : "hello good"
    }
  }
}

# 结果
{
  "error" : {
    "root_cause" : [
      {
        "type" : "query_shard_exception",
        "reason" : "failed to create query: field:[name.doc] was indexed without position data; cannot run PhraseQuery",
        "index_uuid" : "bCDW6OdlQHuW3_EMyP9SwA",
        "index" : "index_options_test"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "index_options_test",
        "node" : "VK0GF1KyQGKmM_0KvgHHnw",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "failed to create query: field:[name.doc] was indexed without position data; cannot run PhraseQuery",
          "index_uuid" : "bCDW6OdlQHuW3_EMyP9SwA",
          "index" : "index_options_test",
          "caused_by" : {
            "type" : "illegal_state_exception",
            "reason" : "field:[name.doc] was indexed without position data; cannot run PhraseQuery"
          }
        }
      }
    ]
  },
  "status" : 400
}

# 搜索,freqs - 不支持短语查询
GET /index_options_test/_search
{
  "query" : {
    "match_phrase" : {
      "name.freq" : "hello good"
    }
  }
}

# 结果
{
  "error" : {
    "root_cause" : [
      {
        "type" : "query_shard_exception",
        "reason" : "failed to create query: field:[name.freq] was indexed without position data; cannot run PhraseQuery",
        "index_uuid" : "bCDW6OdlQHuW3_EMyP9SwA",
        "index" : "index_options_test"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "index_options_test",
        "node" : "VK0GF1KyQGKmM_0KvgHHnw",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "failed to create query: field:[name.freq] was indexed without position data; cannot run PhraseQuery",
          "index_uuid" : "bCDW6OdlQHuW3_EMyP9SwA",
          "index" : "index_options_test",
          "caused_by" : {
            "type" : "illegal_state_exception",
            "reason" : "field:[name.freq] was indexed without position data; cannot run PhraseQuery"
          }
        }
      }
    ]
  },
  "status" : 400
}


# 搜索,offsets - 加速高亮
GET /index_options_test/_search
{
  "query" : {
    "match" : {
      "name.offset" : "hello good"
    }
  },
  "highlight" : {
    "fields" : {
      "name.offset" : {}
    }
  }
}

# 结果
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 0.4132635,
    "hits" : [
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 0.4132635,
        "_source" : {
          "name" : "hello hello good me"
        },
        "highlight" : {
          "name.offset" : [
            "<em>hello</em> <em>hello</em> <em>good</em> me"
          ]
        }
      },
      {
        "_index" : "index_options_test",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.38727614,
        "_source" : {
          "name" : "hello good me"
        },
        "highlight" : {
          "name.offset" : [
            "<em>hello</em> <em>good</em> me"
          ]
        }
      }
    ]
  }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

这是谁的博客?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值