更多喜欢这个关于子文档的查询

时间:2015-10-06 14:28:56

标签: elasticsearch morelikethis

我试图使用More Like This查询在Elasticsearch中获取类似文档。我有一段时间的工作解决方案,但从那时起文档结构已经改变,我们现在每个文档都有一个父级。我无法找到任何表明使用MLT无法找到儿童文件的内容,但这看起来像是什么。任何人都可以解释为什么这不起作用?

我没有收到错误,但结果只是零文件

类型

car: {
  _parent: {
    type: "dealer"
  },
  _routing: {
    required: true
  },
  properties: {
    id: {
      type: "string"
    },
    make: {
      type: "string",
      fields: {
        raw: {
          type: "string",
          index: "not_analyzed"
        }
      }
    },
    model: {
      type: "string",
      fields: {
        raw: {
          type: "string",
          index: "not_analyzed"
        }
      }
    },
    modelGroup: {
      type: "string",
      fields: {
        raw: {
          type: "string",
          index: "not_analyzed"
        }
      }
    },
    modelRaw: {
      type: "string",
      analyzer: "model_raw_analyzer"
    },

    fuel: {
      type: "string",
      fields: {
        raw: {
          type: "string",
          index: "not_analyzed"
        }
      }
    },
    gearbox: {
      type: "string",
      fields: {
        raw: {
          type: "string",
          index: "not_analyzed"
        }
      }
    },
    additionalVehicleData: {
      properties: {
        bodyType: {
          type: "string"
        },
        color: {
          type: "string"
        },
        colorGroup: {
          type: "string"
        },
        cylinderVolumeCC: {
          type: "long"
        },
        engineEffectHp: {
          type: "long"
        },
        engineEffectKw: {
          type: "long"
        },
        enviromentClass: {
          type: "string"
        },
        fourWheelDrive: {
          type: "boolean"
        },
        fuels: {
          properties: {
            co2Emissions: {
              type: "double"
            },
            engineEffectKw: {
              type: "long"
            },
            name: {
              type: "string"
            }
          }
        },
        height: {
          type: "long"
        },
        length: {
          type: "long"
        },
        make: {
          type: "string"
        },
        maxSpeed: {
          type: "string"
        },
        noPassangers: {
          type: "long"
        },
        weight: {
          type: "long"
        },
        width: {
          type: "long"
        }
      }
    },
    bodyType: {
      type: "string",
      fields: {
        raw: {
          type: "string",
          index: "not_analyzed"
        }
      }
    },
    equipment: {
      type: "string",
      index_analyzer: "swedish_edge_ngram",
      search_analyzer: "swedish"
    },
    freetextColor: {
      type: "string",
      fields: {
        raw: {
          type: "string",
          index: "not_analyzed"
        }
      }
    }
    /*** MORE PROPERTIES HERE ... ***/
  }
}
dealer: {
  properties: {
   id: {
      type: "string"
    },
    name: {
      type: "string",
      fields: {
        raw: {
          type: "string",
          index: "not_analyzed"
        }
      }
    }
    /*** MORE PROPERTIES HERE ... ***/
  }
}

我之前使用的查询就像我的主索引和类型car一样简单,其中ID 8379511是有效的汽车ID:

{
  "from": 0,
  "size": 10,
  "query": {
    "more_like_this": {
      "ids": ["8348446"],
      "min_term_freq":1,
      "min_doc_freq":1
      }
  }
}

更改要使用的查询" like_text"而不是" ids"像这样有效,但我并不是因为我想要根据car的更多参数找到搜索结果的逻辑:

{
  "from": 0,
  "size": 10,
  "query": {
    "more_like_this": {
      "like_text": "volvo",
      "min_term_freq":1,
      "min_doc_freq":1
      }
  }
}

这里有什么想法吗?

0 个答案:

没有答案