Searching term in subdocuments with elasticsearch

℡╲_俬逩灬. 提交于 2019-12-08 05:20:47

问题


I have a index document structure like below;

{
   "term":"some term",
   "inlang":"some lang"
   "translations" : {
      {
          "translation":"some translation",
          "outlang":"some lang",
          "translations" : {
              {
                  "translation":"some translation 1"
                  "outlang": "some lang 1"
                  "translations" : {...}
              }
          }
      },
      ...
   } 
}

I want to find a translation in such documents. However, this translation can exists at any level of this document. Is it possible to search term dynamically by using elasticsearch?

For example,

{
   "query": {
      "*.translation":"searchterm"
   }
}

Thanks in advance


回答1:


I have managed to do that with following query;

{
  "query": {
    "query_string": {
      "query": "someterm",
      "fields": ["*.translation"]
    }
  }
}

or

{
  "query": {
    "multi_match": {
      "query": "someterm",
      "fields": ["*.translation"]
    }
  }
}

You can see elasticsearch google group conversation here




回答2:


No, I do not believe this functionality is built into ElasticSearch at the moment. This answer suggests you could build the functionality with a script, but it would be super slow.

In general, ES doesn't play nicely with nested data. It supports nested fields, but many of the more advanced search functionality isn't capable of operating on complex nested data. My suggestion is to denormalize your data so that every translation is represented by a single item in the index, and link between them with ID numbers.



来源:https://stackoverflow.com/questions/13177276/searching-term-in-subdocuments-with-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!