Well,不要刷屏了

More_like_this使用分词器后居然查不出来

Elasticsearch | 作者 401825317 | 发布于2017年07月17日 | 阅读数:6192

elasticsearch版本:5.4.0
插件:ik,pinyin
jvm:1.8
setting:
PUT /testcar/
{
  "index": {
    "analysis": {
      "analyzer": {
        "ik_pinyin_analyzer": {
          "type": "custom",
          "tokenizer": "ik_smart",
          "filter": [
            "my_pinyin",
            "word_delimiter"
          ]
        },
        "ik_analyzer": {
          "type": "custom",
          "tokenizer": "ik_smart",
          "filter": [
            "word_delimiter"
          ]
        }
      },
      "filter": {
        "my_pinyin": {
          
          "type": "pinyin",
          "keep_separate_first_letter": false,
          "keep_full_pinyin": true,
          "keep_original": true,
          "limit_first_letter_length": 16,
          "lowercase": true,
          "remove_duplicated_term": true
        }
      }
    }
  }
}
mapping:
    {
  "properties": {
    "brand": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "brandid": {
      "type": "long"
    },
    "caraddress": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "cc": {
      "type": "long"
    },
    "commentcount": {
      "type": "long"
    },
    "contacts": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "contactsphone": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "createtime": {
      "type": "long"
    },
    "createuser": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "createusertype": {
      "type": "long"
    },
    "des": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "detailspicurl": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "exteriorpicurl": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "favoritescount": {
      "type": "long"
    },
    "firstonthecardtime": {
      "type": "long"
    },
    "flawpicurl": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "from": {
      "type": "long"
    },
    "kilometer": {
      "type": "float"
    },
    "lastupdatetime": {
      "type": "long"
    },
    "licenseplate": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "model": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "modelid": {
      "type": "long"
    },
    "price": {
      "type": "long"
    },
    "province": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "query": {
      "properties": {
        "match_all": {
          "type": "object"
        }
      }
    },
    "secondcarid": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "size": {
      "type": "long"
    },
    "state": {
      "type": "long"
    },
    "style": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "title": {
      "type": "text",
      "fields": {
        "ik": {
          "type": "text",
          "analyzer": "ik_analyzer"
        },
        "ik_pinyin": {
          "type": "text",
          "analyzer": "ik_pinyin_analyzer"
        }
      }
    },
    "transfercount": {
      "type": "long"
    },
    "videodatamodel": {
      "properties": {
        "fileid": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "thumbUrl": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "videoDurantion": {
          "type": "long"
        },
        "videoHeight": {
          "type": "long"
        },
        "videoLength": {
          "type": "long"
        },
        "videoUrl": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "videoWidth": {
          "type": "long"
        }
      }
    },
    "videodatastr": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "viewcount": {
      "type": "long"
    }
  }
}
插入语句:
PUT testcar/secondcar/1
{
  "title":"杜卡迪"
}
PUT testcar/secondcar/2
{
  "title":"杜卡迪Monster"
}
PUT testcar/secondcar/3
{
  "title":"杜卡迪Monster 798"
}
PUT testcar/secondcar/4
{
  "title":"杜卡迪Monster 798 7564"
}
PUT testcar/secondcar/5
{
  "title":"杜卡迪Monster 798ADSADS"
}
PUT testcar/secondcar/6
{
  "title":"杜卡迪Monster 798ADSADS"
}
PUT testcar/secondcar/7
{
  "title":"杜卡迪Monster 798ADSADS"
}
PUT testcar/secondcar/8
{
  "title":"杜卡迪Monster 798ADSADS"
}
PUT testcar/secondcar/9
{
  "title":"杜卡迪Monster 798ADSADS"
}
PUT testcar/secondcar/10
{
  "title":"杜卡迪Monster 798ADSADS"
}
查询语句:
ET testcar/_search
{
  "query": {
    "more_like_this": {
      "fields": [
        "title.ik"
      ],
      "like": "杜卡迪",
      "min_term_freq": 1,
      "max_query_terms": 12
    }
  }
}
result:
{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}
已邀请:

medcl - 今晚打老虎。

赞同来自: 401825317

试试这个

GET testcar/_search
{
"query": {
"more_like_this": {
"fields": [
"title.ik"
],
"like": [
{
"_index": "testcar",
"_type": "secondcar",
"_id": "3"
},
"杜卡迪"
],
"min_doc_freq": 0,
"min_word_len": 0,
"min_term_freq": 0
}
}
}

401825317 - 90后it男

赞同来自:

来个人啊

kepmoving - 90后

赞同来自:

分词后杜卡迪被切开了,没有切除杜卡迪这个词

wangshang

赞同来自:

兄弟,你的问题解决了吗?

kindyywb

赞同来自:

哥们怎么解决的,分享下咯,谢谢。

401825317 - 90后it男

赞同来自:

解决办法是
"min_doc_freq": 0, "min_word_len": 0, "min_term_freq": 0
都设置成0就好,
就是某个词最少得出现几次才可以用morelikethis查到

要回复问题请先登录注册