1

複数の単語を含むフィールド(例:'Name1 Name2'、場合によってはドットとコンマが含まれる)に対して単純なファセット要求を実行しようとしていますが、取得するのは...

 "terms" : [{
    "term" : "Name1",
    "count" : 15
},
{
    "term" : "Name2",
    "count" : 15
}]

だから私のフィールド値はスペースで分割されてからファセットリクエストを実行します...

クエリの例:

curl -XGET http://my_server:9200/idx_occurrence/Occurrence/_search?pretty=true -d '{
  "query": {
    "query_string": {
      "fields": [
        "dataset"
      ],
      "query": "2",
      "default_operator": "AND"
    }
  },
  "facets": {
    "test": {
      "terms": {
        "field": [
          "speciesName"
        ],
        "size": 50000
      }
    }
  }
}'
4

2 に答える 2

6

フィールドを分析したり、少なくともトークン化したりしないでください。トークン化せずにフィールドにインデックスを付ける場合は、マッピングを更新してからインデックスを再作成する必要があります。

于 2012-09-11T18:17:50.580 に答える
4

First of all, javanna provided a very good answer from a practical perspective. However, for the sake of completeness, I want to mention that in some cases there is a way to do it without reindexing the data.

If the speciesName field is stored and your queries produce relatively small number of results, you can use script_field to retrieve stored field values:

curl -XGET http://my_server:9200/idx_occurrence/Occurrence/_search?pretty=true -d '{
  "query": {
    "query_string": {
      "fields": ["dataset"],
      "query": "2",
      "default_operator": "AND"
    }
  },
  "facets": {
    "test": {
      "terms": {
        "script_field": "_fields['\''speciesName'\''].value",
        "size": 50000
      }
    }
  }
}
'

As a result of this query, elasticsearch will retrieve the speciesName field for every record in your result set and it will construct facets from these values. Needless to say, if your result set contains millions of records, performance of this query might be sluggish.

Similarly, if the field is not stored, but record source is stored, you can use script_field facet to retrieve field values from the source:

......
"script_field": "_source['\''speciesName'\'']",
......

Again, source for each record in the result list will be retrieved and parsed, so you might need some patience to run this query on a large set of records.

于 2012-09-12T03:16:47.117 に答える