繁体   English   中英

Elasticsearch Validate API通过类似的方式从单个字段获取突出显示的术语来解释查询词

[英]Elasticsearch validate API explain query terms from more like this against single field getting highlighted terms

我有一个索引,其中包含有效转换后的word或pdf文档纯文本“ document_texts”,该索引建立在Rails堆栈上,ActiveModel是DocumentText,使用的是Elasticsearch Rails gem,用于模型和API。 我希望能够根据文档文本匹配相似的Word文档或pdf文档

我已经能够使用来相互匹配文档

response = DocumentText.search \
  query: {
      filtered: {
          query: {
              more_like_this: {
                  ids: ["12345"]
              }
          }
      }
  }

但是我想看看如何查询结果集,用于匹配文档的查询词是什么

使用elasticsearch API gem,我可以执行以下操作

 client=Elasticsearch::Client.new log:true

 client.indices.validate_query index: 'document_texts',
    explain: true,
    body: {
      query: {
          filtered: {
              query: {
                  more_like_this: {
                      ids: ['12345']
                  }
              }
          }
      }
   }

但是我得到这个回应

{"valid":true,"_shards":{"total":1,"successful":1,"failed":0},"explanations":[{"index":"document_texts","valid":true,"explanation":"+(like:null -_uid:document_text#12345)"}]}

我想找出查询是如何建立的,它最多使用25个术语进行匹配,这25个术语是什么?如何从查询中获取它们?

我不确定是否可行,但我想看看是否可以获取Elasticsearches分析器使用的25个术语,然后根据自己的选择,对这些术语重新使用升值查询。

我也想在文档文本中突出显示此内容,但尝试过

response = DocumentText.search \
  from: 0, size: 25,
  query: {
      filtered: {
          query: {
              more_like_this: {
                  ids: ["12345"]
              }
          },
          filter: {
              bool: {
                  must: [                            
                      {match: { documentable_type: model}}
                 ]
              }
          }

      }
  },
  highlight: {
    pre_tags: ["<tag1>"],
    post_tags: ["</tag1>"],
    fields: {
        doc_text: {
                type_name: {
                content: {term_vector: "with_positions_offsets"}
            }
        }
    }
  }

但这无法产生任何效果,我想我还是很有希望的。 我知道这应该可行,但是希望知道是否有人这样做或最好的方法。 有任何想法吗?

包括一些仅针对其他人的停用词,这将为它提供一种简单的方式来显示用于查询的术语。 它不能解决突出显示问题,但可以提供用于mlt匹配过程的术语。 其他一些设置仅用于显示

  curl -XGET 'http://localhost:9200/document_texts/document_text/_validate/query?rewrite=true' -d '
  {
      "query": {
            "filtered": {
                "query": {
                    "more_like_this": {
                        "ids": ["12345"],
                        "min_term_freq": 1,
                        "max_query_terms": 50,
                        "stop_words": ["this","of"]
                    }
                }
            }
        }
    }'

https://github.com/elastic/elasticsearch-ruby/pull/359

一旦合并,应该会更容易

client.indices.validate_query index: 'document_texts',
  rewrite: true,
  explain: true,
  body: {
    query: {
        filtered: {
            query: {
                more_like_this: {
                    ids: ['10538']
                }
            }
        }
    }
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM