美文网首页ELK漫漫之路
elastic使用中注意项

elastic使用中注意项

作者: 续哥儿 | 来源:发表于2018-08-09 12:22 被阅读0次

    ~以下大部分内容为摘录~
    filter与query对比

    filter,仅仅只是按照搜索条件过滤出需要的数据而已,不计算任何相关度分数,对相关度没有任何影响
    query,会去计算每个document相对于搜索条件的相关度,并按照相关度进行排序

    一般来说,如果你是在进行搜索,需要将最匹配搜索条件的数据先返回,那么用query;如果你只是要根据一些条件筛选出一部分数据,不关注其排序,那么用filter
    除非是你的这些搜索条件,你希望越符合这些搜索条件的document越排在前面返回,那么这些搜索条件要放在query中;如果你不希望一些搜索条件来影响你的document排序,那么就放在filter中即可

    filter与query性能

    filter,不需要计算相关度分数,不需要按照相关度分数进行排序,同时还有内置的自动cache最常使用filter的数据
    query,相反,要计算相关度分数,按照分数进行排序,而且无法cache结果

    GET /test_index/_search
    {
        "query": {
                "bool": {
                    "must": { "match":   { "name": "tom" }},
                    "should": [
                        { "match":       { "hired": true }},
                        { "bool": {
                            "must":      { "match": { "personality": "good" }},
                            "must_not":  { "match": { "rude": true }}
                        }}
                    ],
                    "minimum_should_match": 1
                }
        }
    }
    

    should 最好要配合"minimum_should_match": 1来使用

    _validate/query?explain 这个API 可以用来验证所写的搜索是否合法

    dynamic策略

    true:遇到陌生字段,就进行dynamic mapping
    false:遇到陌生字段,就忽略
    strict:遇到陌生字段,就报错

    PUT /my_index
    {
      "mappings": {
        "my_type": {
          "dynamic": "strict",
          "properties": {
            "title": {
              "type": "text"
            },
            "address": {
              "type": "object",
              "dynamic": "true"
            }
          }
        }
      }
    }
    

    相关文章

      网友评论

        本文标题:elastic使用中注意项

        本文链接:https://www.haomeiwen.com/subject/dmhdvftx.html